











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Padua-Perez; Class: OBJECT-ORIENTED PROG II; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;
Typology: Study notes
1 / 19
This page cannot be seen from the preview
Don't miss anything!












Overview
Types of errors Exceptions Testing Debugging
Program Errors – Compile Time
Errors in code construction
Lexical (typographical), grammatical, types Detected during compilation Usually easy to correct quickly
Misspelled keyword Missing or misplaced symbol Incorrect operator for variable type
Program Errors – Run Time
Operations illegal / impossible to execute Detected during program execution
But not detectable at compile time Treated as
exceptions
in Java
Division by zero Array index out of bounds Using null pointer Illegal format conversion
Exceptions
Usually a
run-time error
Division by zero Access past end of array Out of memory Number input in wrong format (float vs. integer) Unable to write output to file Missing input file
Exception Handling – Throw Exception
Throw exception
if (error)
throw
new ExceptionType();
try {
} catch
(ExceptionType e) { ...action... }
Java exception backtracks tocaller(s) until matching catchblock found
Generating & Handling Exceptions^ Java primitives
Try Throw Catch Finally
Enclose code generating exceptions in
try
block
Use
throw
to actually generate exception
Use
catch
to specify exception handlers
Use
finally
to specify actions after exception
Java Syntax
try
// try block encloses throws
throw
new eType1();
// throw
jumps
to catch
} catch
(eType1 e) {
// catch block 1
...action...
// run if type match
} catch
(eType2 e) {
// catch block 2
...action...
// run if type match
} finally
// final block
...action...
// always executes
Exceptions – Examples
throw new UnsupportedOperationException(
"You must implement this method.");
If method is invoked during program execution Exception is thrown
Of type UnsupportedOperationException Message string is displayed Program execution stops unless exception caught
Testing
Detects
run-time error
if exception thrown
Detects
logic error
if behavior is incorrect
Selecting test cases Testing different parts of program Visibility of program code
Debugging – Approaches
Insert debugging statements Trace program control flow Display value of variables
IDE (integrated development environment) Interactive debugger
Interactive Debugger
Provides trace of program execution Shows location in code where error encountered Interactive program execution
Single step
through code
Run to
breakpoints
Displays values of variables
For current state of program
Interactive Debugger
Specify location(s) in code Execute program until breakpoint encountered Can skip past uninteresting code