
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Exception Bubbling
|
267
// Meanwhile, elsewhere in the program...
// INTERPRETER: Aha! Found a try block that has a catch block whose
// parameter's datatype is Error! My work's done. catch block,
// please execute now...
try {
ErrorDemo.startApp( );
} catch (e:Error) {
// Handle problems...
trace("Exception caught where Error.startApp( ) was invoked.");
}
Notice that the interpreter finds the try/catch block despite the fact that it surrounds
not the error-throwing method, nor the caller of the error-throwing method, but the
caller of the method that called the error-throwing method!
Uncaught Exceptions
We’ve seen a number of scenarios in which we’ve caught (trapped) various errors.
But what happens if the interpreter never finds a catch block that can handle the
thrown exception? If no eligible catch block is found anywhere in the call stack, then
the interpreter:
• Sends the value of the thrown Error object’s
message property to the Output
panel (or simply sends the thrown expression itself if it wasn’t an Error object)
• Aborts execution of all code currently remaining in the call stack (including
frame scripts and callback functions such as a setInterval( ) callback)
Execution of the program then resumes normally. For example, if an uncaught
exception occurs on frame 1, layer 1 of a