
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
268
|
Chapter 10: Exceptions
// INTERPRETER: Hmm. Well, I searched all the way to the top, and still
// no try block. I'll send "Something went wrong" to the Output
// panel. Maybe the programmer will know what to do.
ErrorDemo.startApp( );
As we’ve just seen, because exceptions bubble up the call stack, it’s not necessary for
a method to catch its own exceptions. And it’s not even necessary for the caller of a
method to catch its exceptions. The exception can legally be caught at any level in the
call stack. Any method can delegate exception handling to the code that calls it. That
said, it’s bad form and harmful to a program to throw an exception and then never
catch it. You should always catch exceptions or, having encountered an uncaught
exception, revise your code so that the exception isn’t thrown in the first place.
Unfortunately, there’s no way in ActionScript to tell the compiler to force a program
to catch its own exceptions. As we’ll learn later, ActionScript does not support Java-
style checked exceptions, which are exceptions that must be caught in order for a pro-
gram to compile. In Java terminology, all exceptions in ActionScript are unchecked.
The finally Block
So far, we’ve discussed only the try and catch blocks in the try/catch/finally statement.
As we’ve seen, a try