
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
278
|
Chapter 10: Exceptions
Exceptions are, hence, harder to work with in ActionScript than in languages that
support compile-time errors for uncaught exceptions. In Java, for example, an excep-
tion can be either checked (a compile-time error occurs if the exception is not han-
dled) or unchecked (no compile-time error occurs if the exception is not handled).
In Java, the declaration for a method that throws a checked exception explicitly
includes the exception in the method header. Here’s a Java method declaration that
explicitly states the type of exception the method can throw (in this case the method
can throw exceptions of type IOException):
public void someMethod( ) throws IOException {
}
Upon reading the preceding method declaration, the programmer immediately
knows she must handle IOExceptions when invoking the method. If the programmer
invokes the method without catching or rethrowing the exception, Java will produce
an error and the program will not compile. This strictness forces programmers to
dutifully deal with exceptions, leading to less time debugging exception-related
errors. ActionScript doesn’t support the throws clause in method declarations.
No Built-in Exceptions
We saw earlier that Flash doesn’t throw an exception when a developer attempts an
illegal operation,