Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 262

Programming actionscript 3.0
Table of Contents

Advertisement

The
statement encloses statements that will execute whether or not an error occurs
finally
in the
block. If there is no error, the statements within the
try
the
block statements complete. If there is an error, the appropriate
try
executes first, followed by the statements in the
The following code demonstrates the syntax for using the
try
{
// some code that could throw an error
}
catch (err:Error)
{
// code to react to the error
}
finally
{
// Code that runs whether or not an error was thrown. This code can clean
// up after the error, or take steps to keep the application running.
}
Each
statement identifies a specific type of exception that it handles. The
catch
statement can specify only error classes that are subclasses of the Error class. Each
statement is checked in order. Only the first
thrown will execute. In other words, if you first check the higher-level Error class and then a
subclass of the Error class, only the higher-level Error class will match. The following code
illustrates this point:
try
{
throw new ArgumentError("I am an ArgumentError");
}
catch (error:Error)
{
trace("<Error> " + error.message);
}
catch (error:ArgumentError)
{
trace("<ArgumentError> " + error.message);
}
The previous code displays the following output:
<Error> I am an ArgumentError
In order to correctly catch the ArgumentError, you need to make sure that the most specific
error types are listed first, and the more generic error types are listed later, as the following
code shows:
try
{
262
Handling Errors
finally
block.
finally
try..catch..finally
statement that matches the type of error
catch
block execute after
statement
catch
statements:
catch
catch

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents