Section 2.4: Errors. Common errors ● Mismatched parentheses ● Omitting space after operator or between numbers ● Putting operator between operands.

Slides:



Advertisements
Similar presentations
Chapter 5 Errors Bjarne Stroustrup
Advertisements

VARIABLES AND DEBUGGING Beginning Programming. Assignment Statements  Used to hold values in a variable  Calculates a result and stores it in a variable.
Coding and Debugging. Requirements and Specification Recall the four steps of problem solving: Orient, Plan, Execute, Test Before you start the implementation.
Why care about debugging? How many of you have written a program that worked perfectly the first time? No one (including me!) writes a program that works.
Programming Types of Testing.
Programming in Visual Basic
Debugging Introduction to Computing Science and Programming I.
C Language Elements (II) H&K Chapter 2 Instructor – Gokcen Cilingir Cpt S 121 (June 22, 2011) Washington State University.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Announcements The first graded lab will be posted Sunday 2/15 and due Friday 2/27 at midnight It is brand new, so please don’t hand in last semester’s.
CSC 160 Computer Programming for Non-Majors Lecture #3: Calling Functions Prof. Adam M. Wittenstein
Section 1.1: Flying a UFO (continued). Conversion recipe 1)Expand abbreviations 2)Parenthesize all subexpressions that have an operator. Should end up.
How to Debug VB .NET Code.
Section 4.3: Conditions and Conditional Functions.
CSC 160 Computer Programming for Non-Majors Lecture #10: Conditionals I Prof. Adam M. Wittenstein
Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
CSC 160 Computer Programming for Non-Majors Lecture #7: Variables Revisited Prof. Adam M. Wittenstein
CSC 160 Computer Programming for Non-Majors Lecture #5 (continued): More on Writing Functions Prof. Adam M. Wittenstein
Fundamentals of Python: From First Programs Through Data Structures
ITP © Ron Poet Lecture 1 1 IT Programming Introduction.
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
19/5/2015CS150 Introduction to Computer Science 1 Announcements  1st Assignment due next Monday, Sep 15, 2003  1st Exam next Friday, Sep 19, 2003  1st.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Programming Translators.
DEBUGGING CHAPTER Topics  Getting Started with Debugging  Types of Bugs –Compile-Time Bugs –Bugs Attaching Scripts –Runtime Errors  Stepping.
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Relations And Functions. A relation from non empty set A to a non empty set B is a subset of cartesian product of A x B. This is a relation The domain.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Factoring a polynomial means expressing it as a product of other polynomials.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CPS120: Introduction to Computer Science Decision Making in Programs.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
BMTRY 789 Lecture 11: Debugging Readings – Chapter 10 (3 rd Ed) from “The Little SAS Book” Lab Problems – None Homework Due – None Final Project Presentations.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Relations And Functions. A relation is a set of ordered pairs {(2,3), (-1,5), (4,-2), (9,9), (0,-6)} This is a relation The domain is the set of all x.
Functional Programming Language 1. A program is: Composition of operations on data Characteristics (in pure form): –Name values, not memory locations.
Debugging, Escape Command, More Math. It’s your birthday!  Write a program that asks the user for their name and their age.  Figure out what their birth.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Types of factoring put the title 1-6 on the inside of your foldable and #7 on the back separating them into sum and cubes 1.Greatest Common Factor 2.Difference.
Controlling Program Flow with Decision Structures.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Warm Up What algebraic equation shows the sentence four plus a number divided by six is equal to the product of twelve and the same number?
For Monday Read pages Do exercise 1.1 on page 46 (to hand in – may be done in groups of up to 4) Complete WebCT quiz.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
CS 115 Lecture 5 Math library; building a project Taken from notes by Dr. Neil Moore.
Functions Wouldn’t it be nice to be able to bring up a new animal and paragraph without having to reload the page each time? We can! We can place the.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Few More Math Operators
CMPT 120 Topic: Python’s building blocks -> More Statements
5.01 Understand Different Types of Programming Errors
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
5.01 Understand Different Types of Programming Errors
Teaching London Computing
T. Jumana Abu Shmais – AOU - Riyadh
Spot the bug!.
Computing Fundamentals
Relations And Functions © 2002 by Shawna Haider.
Relations And Functions.
Relations And Functions.
Learning Intention I will learn about the different types of programming errors.
Review of Previous Lesson
WJEC GCSE Computer Science
CHAPTER 6 Testing and Debugging.
Chapter 5 JavaScript Numbers and Expressions
Presentation transcript:

Section 2.4: Errors

Common errors ● Mismatched parentheses ● Omitting space after operator or between numbers ● Putting operator between operands

Tracking Mistakes ● Computer programs never work right on the first try ● Need to analyze errors – Symptoms – Diagnosis – Treatment – Prevention

Symptoms ● Error message; if so, read it! ● Wrong answers; if so, look for patterns – answer always wrong in the same way? – answer right on some inputs, wrong on others? ● No answers at all

Diagnosis What did I do to cause the error? ● Matching parentheses, braces, quotation marks, etc. ● Misspellings & typoes ● Calling function w/wrong number or wrong type of arguments ● Wrong formula ● Inadequate test cases ● etc. ● Free-form comments

Treatment & prevention ● For mismatched parentheses, quotation marks, misspellings, etc. obvious ● If fixing the problem took thought, write down how you fixed it

Analyzing Errors in Math In math class… 1) do the problem 2) pray that you got it right 3) check the back of the book 4) “aw, shucks, I got it wrong” 5) go on to the next problem anyway ● This won’t work in a programming class! ● Nothing will work right on the first try! ● Prayer won’t help much.

Analyzing Errors in Programming In programming class… 1) do the problem 2) pray that you got it right 3) test it 4) “aw, shucks, I got it wrong” 5) Identify how it was wrong 6) Find something in your program that could cause that 7) Fix it 8) go back to step 3

Kinds of Errors ● Syntax (i.e. grammar) – DrScheme “Check Syntax” catches, and gives helpful error messages, highlighting where program is wrong – Examples: misspellings, mismatched parentheses ● Run-time error messages – DrScheme “Run” catches, and gives sorta-helpful error messages, with a guess at where program is wrong – Examples: wrong number of arguments, wrong type arguments, division by zero ● Logical error messages (aka “bugs”) – No error message; you have to recognize that the answer (or behavior) is wrong. You have to figure out where. – Examples: + where you meant *, <= where you meant <, wrong order…

Exercise 2.4.2: Syntax Errors ● The following are all illegal programs in Scheme because of a syntax mistake. ● Type in the program and execute it. ● You will get an error message. ● Fix something and execute again. ● Repeat until there is no error messages. ● Then type in the next program and repeat.

Exercise 2.4.2: Syntax Errors (define (f 1) (+ x 10)) (define g x) + x 10) (define h(x) (+ x 10))

Exercise 2.4.2: Syntax Errors (define f 1) (+ x 10)); the number 1 cannot be a variable (define g x) + x 10) (define h(x) (+ x 10))

Exercise 2.4.2: Syntax Errors (define f 1) (+ x 10)); the number 1 cannot be a variable (define g x) + x 10); there is no left parenthesis next to ; operator + (define h(x) (+ x 10))

Exercise 2.4.2: Syntax Errors (define f 1) (+ x 10)); the number 1 cannot be a variable (define g x) + x 10); there is no left parenthesis next to ; operator + (define h(x) (+ x 10)); do not include the variable x in ; parentheses

Exercise 2.4.4: Run-time Errors ● Enter the following grammatically legal Scheme program into the Definitions window. (define (somef x) (sin x x)) ● Click Run. ● Then, in the Interactions window, evaluate: (somef 10 20) (somef 10) ● Read the error messages. ● Also observe what DrScheme highlights.

Exercise 2.4.4: Run-time Errors ● Enter the following grammatically legal Scheme program into the Definitions window. (define (somef x) (sin x x)) ● Click Run. ● Then, in the Interactions window, evaluate: (somef 10 20) somef: this procedure expects 1 argument, here it is provided 2 arguments (somef 10) sin: expects 1 argument, given 2: ● Read the error messages. ● Also observe what DrScheme highlights.

Logical Errors Logical errors (aka “bugs”) are the hardest to fix. To prevent them: ● Choose good test cases in advance – At least one for each “category” of input or output – If input involves ranges of numbers, test borderline cases – Find as many bugs as you can; if you don’t find them, I will! ● Look for patterns of wrong answers: – All answers are wrong in the same way (e.g. negative or reciprocal of right answer) – Borderline cases are wrong – Borderline cases are right; everything else is wrong – Simplest cases are right; more complicated ones are all wrong ● Use Stepper to spot where program “goes off the rails”

In summary… ● A syntax error is caused by not following all the rules when writing a Scheme function. ● A runtime error is caused when an example or test case is not consistent with its corresponding Scheme function (either the function or the example may be wrong). ● A logical error means that you have followed all the rules of Scheme, but your Scheme function doesn’t make sense in real life. An example, is writing a Scheme function that divides the length and width to find the area.