ch11 - Exception handling Exceptionan indication of a...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Exception handling Exception —an indication of a problem that occurs during a program’s execution. The name “exception” implies that the problem occurs infrequently. With exception handling, a program can continue executing (rather than terminating) after dealing with a problem. Mission-critical or business-critical computing. Robust and fault-tolerant programs (i.e., programs that can deal with problems as they arise and continue executing).
Background image of page 2
ArrayIndexOutOfBoundsException occurs when an attempt is made to access an element past either end of an array. ClassCastException occurs when an attempt is made to cast an object that does not have an is-a relationship with the type specified in the cast operator. A NullPointerException occurs when a null reference is used where an object is expected. Only classes that extend Throwable (package java.lang ) directly or indirectly can be used with exception handling.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Programs frequently test conditions to determine how program execution should proceed. Consider the following pseudocode: Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding task did not execute correctly Perform error processing Begins by performing a task; then tests whether it executed correctly. x If not, perform error processing. x Otherwise, continue with the next task. Intermixing program and error-handling logic in this manner can make programs difficult to read, modify, maintain and debug— especially in large applications.
Background image of page 4
Exception handling enables you to remove error- handling code from the “main line” of program execution Improves program clarity Enhances modifiability Handle any exceptions you choose All exceptions All exceptions of a certain type All exceptions of a group of related types (i.e., related through a superclass). Such flexibility reduces the likelihood that errors will be overlooked, thus making programs more robust.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Exceptions are thrown (i.e., the exception occurs) when a method detects a problem and is unable to handle it. Stack trace
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/06/2010 for the course CS 2050 taught by Professor Uhlmann during the Fall '09 term at Missouri (Mizzou).

Page1 / 33

ch11 - Exception handling Exceptionan indication of a...

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

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