Lecture 6 - Errors

Lecture 6 - Errors - Errors Lecture 6 Hartmut Kaiser...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Errors Lecture 6 Hartmut Kaiser [email protected] http://www.cct.lsu.edu/˜hkaiser/fall_2011/csc1254.html
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Abstract When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. Here, we’ll concentrate on a key area: how to deal with unexpected function arguments. We’ll also discuss techniques for finding errors in programs: debugging and testing. 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 2
Background image of page 2
Overview Kinds of errors Argument checking ▫ Error reporting ▫ Error detection ▫ Exceptions Debugging Testing 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Errors “ … I realized that from now on a large part of my life would be spent finding and correcting my own mistakes.” ▫ Maurice Wilkes, 1949 When we write programs, errors are natural and unavoidable; the question is, how do we deal with them? ▫ Organize software to minimize errors. ▫ Eliminate most of the errors we made anyway. Debugging Testing ▫ Make sure the remaining errors are not serious. My guess is that avoiding, finding, and correcting errors is 95% or more of the effort for serious software development. ▫ You can do much better for small programs. or worse, if you’re sloppy 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 4
Background image of page 4
Your Program 1. Should produce the desired results for all legal inputs 2. Should give reasonable error messages for illegal inputs 3. Need not worry about misbehaving hardware 4. Need not worry about misbehaving system software 5. Is allowed to terminate after finding an error 3, 4, and 5 are true for beginner’s code; often, we have to worry about those in real software. 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sources of Errors Poor specification ▫ “What’s this supposed to do?” Incomplete programs ▫ “but I’ll not get around to doing that until tomorrow” Unexpected arguments ▫ “but sqrt() isn’t supposed to be called with -1 as its argument” Unexpected input ▫ “but the user was supposed to input an integer” Code that simply doesn’t do what it was supposed to do ▫ “so fix it!” 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 6
Background image of page 6
Kinds of Errors Compile-time errors ▫ Syntax errors ▫ Type errors Link-time errors Run-time errors ▫ Detected by computer (crash) ▫ Detected by library (exceptions) ▫ Detected by user code Logic errors ▫ Detected by programmer (code runs, but produces incorrect output) 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Check your Inputs Before trying to use an input value, check that it meets your expectations/requirements ▫ Function arguments ▫ Data from input (istream) 9/8/2011, Lecture 6 CSC 1254, Fall 2011, Errors 8
Background image of page 8
Bad Function Arguments The compiler helps: ▫ Number and types of arguments must match int area( int length, int width) { return length*width;
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2011 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 31

Lecture 6 - Errors - Errors Lecture 6 Hartmut Kaiser...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online