User Guide

255
9
CHAPTER 9
Handling Errors
To “handle” an error means you build logic into your application that responds to, or fixes, an
error, generated either when an application is compiled or when a compiled application is
running. When your application handles errors, something occurs as a response when the error
is encountered, as opposed to no response and whatever process created the error failing
silently. Used correctly, error handling helps shield your application and its users from
otherwise unexpected behavior.
However, error handling is a broad category that includes responding to many kinds of errors
that are thrown during compilation or at run time. This chapter focuses on how to handle
run-time errors, the different types of errors that can be generated, and the advantages of the
new error handling system in ActionScript 3.0. This chapter also explains how to implement
your own custom error handling strategies for your applications.
Contents
Types of errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .256
Error handling in ActionScript 3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .258
Working with the debugger version of Flash Player . . . . . . . . . . . . . . . . . . . . . . . . . 260
Handling synchronous errors in an application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Creating custom error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .266
Responding to error events and status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .267
Comparing the Error classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Example: CustomErrors application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277