
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
264
|
Chapter 10: Exceptions
Remember, error granularity is a choice. In option 4 we created a custom Error sub-
class for each variety of exception generated by the Box class. This approach gives
our program the greatest ability to respond independently to different types of errors.
But such flexibility is not necessarily required in many situations. Let the needs of
your program’s logic dictate how granular you make your errors.
In the first release of the Flash MX 2004 authoring tool, a bug pre-
vents catch statements from executing when the catch parameter
datatype refers to a class that has been imported via the import state-
ment. For example, in the following code, the catch statement never
executes because SomeCustomError is imported:
import somePackage.SomeCustomError;
try {
throw new SomeCustomError( );
} catch(e:SomeCustomError) {
// This code should execute but it does not
// if the movie is compiled with version 7.0
// of the Flash MX 2004 authoring tool.
trace("Caught: " + e);
}
To work around the problem, we can include the full package name when specifying
a custom error class as a catch block parameter. For example:
import somePackage.SomeCustomError;
try {
throw new SomeCustomError( );
} catch(e:somePackage.SomeCustomError) {
// Now that the package name is included, this ...