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 doesn’t 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.
NO
T
E
The finally block executes even if the try block exits using a return statement
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...