User Guide
Handling synchronous errors in an application 261
{
tf.text = error.toString();
}
If the readBoolean() method threw an EOFError in the debugger version of Flash Player,
the following message would be displayed in the
tf text field: “EOFError: Error #2030: End
of file was encountered.”
The same code in a release version of Flash Player would display the following text:
“EOFError: Error #2030.”
In order to keep Flash Player’s resources and size to a minimum in the release version, error
message strings are not present. You can look up the error number in the documentation (the
appendixes of the ActionScript 3.0 Language Reference) to correlate to an error message.
Alternatively, you can reproduce the error using the debugger version of Flash Player to see the
full message.
Handling synchronous errors in an
application
The most common error handling is synchronous error handling logic, where you insert
statments into your code to catch synchronous errors at run time. This type of error handling
lets your application notice and recover from run-time errors when functions fail. The logic
for catching a synchronous error includes
try..catch..finally statements, which literally
try an operation, catch any error response from Flash Player, and finally execute some other
operation to handle the failed operation.
Using try..catch..finally statements
When you work with synchronous run-time errors, use the try..catch..finally
statements to catch errors. When a run-time error occurs, Flash Player throws an exception,
which means that Flash Player suspends normal execution and creates a special object of type
Error. The Error object is then thrown to the first available
catch block.
The
try statement encloses statements that have the potential to create errors. You always use
the
catch statement with a try statement. If an error is detected in one of the statements in
the
try statement block, the catch statements that are attached to that try statement will
execute.