lec29March1908

lec29March1908 - for a method that contains a block of code...

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

View Full Document Right Arrow Icon
Lecture 29 March 19, 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
Exceptions Used to handle errors and other exceptional events An event which occurs during the execution of a program that disrupts the normal flow of the program’s instructions An exception is an object that describes an unusual or erroneous situation
Background image of page 2
e.g.
Background image of page 3

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

View Full DocumentRight Arrow Icon
When an error occurs within a method, the method creates an object And Hands it off to the runtime system.
Background image of page 4
The object created is called An exception object Has information about the error Type, state of the program when the error was created Creating this object and handing it to the runtime system is called Throwing an exception
Background image of page 5

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

View Full DocumentRight Arrow Icon
After a method throws an exception, the runtime, the runtime system attempts to find something to handle it The set of “somethings” to handle the exception is the ordered list of methods that had been called to get to the method where the error occured
Background image of page 6
This list of method is call stack The runtime system searches the call stack
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

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

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15

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

View Full DocumentRight Arrow Icon
Background image of page 16
Background image of page 17
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for a method that contains a block of code that can handle the exception block of code: exception handler Search begins with the method in which the error occurred and proceeds through the call stack in the reverse order in which methods were called The exception handler chosen is said to catch the exception If the runtime system searches the call stack without finding an appropriate exception handler, the runtime system and the program terminate Why? Separating error-handling code from regular code Propogating errors up the call stack Grouping and differentiating errors types The code that might throw certain exceptions must be enclosed by either of the following: Try statement Provides a handler for the exception A method that specifies that it can throw the exception Provides a throws clause that lists the exception...
View Full Document

Page1 / 17

lec29March1908 - for a method that contains a block of code...

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

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