(6) Program Correctness and Exceptions

(6) Program Correctness and Exceptions - Reading CMSC 132:...

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

View Full Document Right Arrow Icon
1 CMSC 132: Object-Oriented Programming II Program Correctness, Exceptions Department of Computer Science University of Maryland, College Park 2 Reading Read Sections 2.1-2.7 in the Koffman text (material covered partly in Sections 1.6 and 2.11 in the second edition) 3 Overview Program correctness is determined by the presence or absence of program defects or bugs (which cause errors ) Topics to be discussed: Types of errors Testing Debugging Exceptions 4 Errors Errors refer to rare events outside the normal behavior of code Examples: Division by zero Accessing outside of an array Out of memory Number input in wrong format (float vs. integer) Unable to write output to file Missing input file
Background image of page 1

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

View Full DocumentRight Arrow Icon
5 Types of program errors Compile-time (syntax) errors Runtime errors Logic errors 6 Compile-time (syntax) errors Characteristics: Errors in code construction, such as typographical, grammatical, or type mismatch mistakes Are usually the kind of errors that can be corrected most quickly Examples: Misspelled keywords Extra, missing, or misplaced symbols Incorrect operator for the type of variable it's applied to 7 Runtime errors Characteristics: Operations that are illegal or impossible to execute Are detected during program execution, but not detectable at compile time Treated as exceptions in Java Examples: Division by zero Array index out of bounds Using a null reference Illegal format conversion 8 Logic errors Characteristics: These are operations leading to an incorrect program state They may- or may not- lead to runtime errors They represent a problem in the design or implementation of the algorithm used Examples: Computing an incorrect arithmetic value Ignoring an illegal input These are the hardest types of errors to handle They are detected by testing They are fixed by debugging
Background image of page 2
9 Testing Testing means to run a program (or part of it) under controlled conditions to verify its behavior Detects runtime errors if an exception is thrown Detects logic errors if the behavior is observed to be incorrect Some issues involved in testing: Selecting test cases Testing different parts of a program Visibility of program code Test coverage 10 Test coverage Test coverage Whether code is executed by some test case Certain test coverage metrics are automatically calculated by the CMSC project submission server we will be using: For a set of tests selected (from link), e.g., student tests, public tests, student and public tests For conditionals, it reports X/Y where X is the number of tests executing with condition true Y is the number of tests executing with condition false Green means executed by some test case, and pink means not executed by any test case 11 Submit server test coverage example 12 Debugging Debugging is the process of finding and fixing software errors, after runtime errors occur or testing detects them Goal: Determine the cause of runtime and and logic errors Correct errors found, without introducing new ones Similar to detective work Carefully inspect the information in the program: code, values of variables, and program behavior
Background image of page 3

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

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

This note was uploaded on 11/16/2011 for the course CMSC 132 taught by Professor Padua-perez during the Fall '08 term at Maryland.

Page1 / 10

(6) Program Correctness and Exceptions - Reading CMSC 132:...

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

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