User Guide

256 Handling Errors
Types of errors
When you develop and run applications, you encounter different types of errors and error
terminology. The following list introduces the major error types and terms:
Compile-time errors are raised by the ActionScript compiler during code compilation.
Compile-time errors occur when syntactical problems in your code prevent your
application from being built.
Run-time errors occur when you run your application after you compile it. Run-time errors
represent errors that are caused while a SWF file plays in Adobe Flash Player 9. In most
cases, you will be able to handle run-time errors as they occur, reporting them to the user
and taking steps to keep your application running. If the error is a fatal error, such as not
being able to connect to a remote website or load required data, you can use error
handling to allow your application to finish gracefully.
Synchronous errors are run-time errors that occur at the time a function is invoked—for
example, when you try to use a specific method and the argument you pass to the method
is invalid, so Flash Player throws an exception. Most errors occur synchronously—at the
time the statement executes—and the flow of control passes immediately to the most
applicable
catch statement.
For example, the following code excerpt throws a run-time error because the
browse()
method is not called before the program attempts to upload a file:
var fileRef:FileReference = new FileReference();
try
{
fileRef.upload("http://www.yourdomain.com/fileupload.cfm");
}
catch (error:IllegalOperationError)
{
trace(error);
// Error #2037: Functions called in incorrect sequence, or earlier
// call was unsuccessful.
}
In this case, a run-time error is thrown synchronously because Flash Player determined
that the
browse() method was not called before the file upload was attempted.
For detailed information on synchronous error handling, see “Handling synchronous
errors in an application” on page 261.