User Guide

218 ActionScript language elements
If the exception thrown is an object, the type will match if the thrown object is a subclass of
the specified type. If an error of a specific type is thrown, the
catch block that handles the
corresponding error is executed. If an exception that is not of the specified type is thrown, the
catch block does not execute and the exception is automatically thrown out of the try block
to a
catch handler that matches it.
If an error is thrown within a function, and the function does not include a
catch handler,
then the ActionScript interpreter exits that function, as well as any caller functions, until a
catch block is found. During this process, finally handlers are called at all levels.
Availability: ActionScript 1.0; Flash Lite 2.0
Parameters
error:Object - The expression thrown from a throw statement, typically an instance of the
Error class or one of its subclasses.
Example
The following example shows how to create a
try..finally statement. Because code in the
finally block is guaranteed to execute, it is typically used to perform any necessary clean-up
after a
try block executes. In the following example, setInterval()calls a function every
1000 millisecond (1 second). If an error occurs, an error is thrown and is caught by the
catch
block. The finally block is always executed whether or not an error occurs. Because
setInterval() is used, clearInterval() must be placed in the finally block to ensure
that the interval is cleared from memory.
myFunction = function () {
trace("this is myFunction");
};
try {
myInterval = setInterval(this, "myFunction", 1000);
throw new Error("my error");
}
catch (myError:Error) {
trace("error caught: "+myError);
}
finally {
clearInterval(myInterval);
trace("error is cleared");
}