03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

try..catch..finally statement<br />

try {// ... try block ... } finally { // ... finally block ... }<br />

try { // ... try block ... }<br />

catch(error [:ErrorType1]) // ... catch block ... }<br />

[catch(error[:ErrorTypeN]) { // ... catch block ... }]<br />

[finally { // ... finally block ... }]<br />

Enclose a block of code in which an error can occur, <strong>and</strong> then respond to the error. If any code<br />

within the try code block throws an error (using the throw statement), control passes to the<br />

catch block, if one exists, <strong>and</strong> then to the finally code block, if one exists. The finally<br />

block always executes, regardless of whether an error was thrown. If code within the try block<br />

doesn't throw an error (that is, if the try block completes normally), then the code in the<br />

finally block is still executed. The finally block executes even if the try block exits using<br />

a return statement.<br />

A try block must be followed by a catch block, a finally block, or both. A single try block<br />

can have multiple catch blocks but only one finally block. You can nest try blocks as<br />

many levels deep as desired.<br />

The error parameter specified in a catch h<strong>and</strong>ler must be a simple identifier such as e or<br />

theException or x. The variable in a catch h<strong>and</strong>ler can also be typed. When used with<br />

multiple catch blocks, typed errors let you catch multiple types of errors thrown from a single<br />

try block.<br />

If the exception thrown is an object, the type will match if the thrown object is a subclass of<br />

the specified type. If an error of a specific type is thrown, the catch block that h<strong>and</strong>les the<br />

corresponding error is executed. If an exception that is not of the specified type is thrown, the<br />

catch block does not execute <strong>and</strong> the exception is automatically thrown out of the try block<br />

to a catch h<strong>and</strong>ler that matches it.<br />

If an error is thrown within a function, <strong>and</strong> the function does not include a catch h<strong>and</strong>ler,<br />

then the ActionScript interpreter exits that function, as well as any caller functions, until a<br />

catch block is found. During this process, finally h<strong>and</strong>lers are called at all levels.<br />

Parameters<br />

error:Object - The expression thrown from a throw statement, typically an instance of the<br />

Error class or one of its subclasses.<br />

202 ActionScript language elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!