EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 149

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
About statements 149
Using try..catch and try..catch..finally statements
Using try..catch..finally blocks lets you add error handling to your Flash applications.
The
try..catch..finally keywords let you enclose a block of code where an error can
occur and respond to that error. If any code within the
try code block throws an error (using
the
throw statement), control passes to the catch block, if one exists. Then control passes to
the
finally code block, if one exists. The optional finally block always executes, regardless
of whether an error was thrown.
If code within the
try block doesnt throw an error (that is, the try block completes
normally), the code in the
finally block still executes.
You write
try..catch and try..catch..finally statements using the following format:
// try-catch
try {
// statements
} catch (myError) {
// statements
}
// try-catch-finally
try {
// statements
} catch (myError) {
// statements
} finally {
// statements
}
Any time your code throws an error, you can write custom handlers to handle the error
gracefully and take appropriate actions. You might need to try loading external data from a
web service or text file or to display an error message to the end user. You can even use the
catch block to try to connect to a web service that alerts an administrator that a particular
error occurred, so he or she can make sure the application works properly.
NOTE
The finally block executes even if the try block exits using a return statement

Table of Contents

Related product manuals