User Guide
Responding to error events and status 267
The following shows an example of using AppError in your project:
try
{
throw new AppError("Encountered Custom AppError", 29);
}
catch (error:AppError)
{
trace(error.errorID + ": " + error.message)
}
Responding to error events and status
One of the most noticeable improvements to error handling in ActionScript 3.0 is the support
for error event handling for responding to asynchronous run-time errors. (For a definition of
asynchronous errors, see “Types of errors” on page 256.)
You can create event listeners and event handlers to respond to the error events. Many classes
dispatch error events the same way they dispatch other events. For example, an instance of the
XMLSocket class normally dispatches three types of events:
Event.CLOSE, Event.CONNECT,
and
DataEvent.DATA. However, when a problem occurs, the XMLSocket class can dispatch
the
IOErrorEvent.IOError or the SecurityErrorEvent.SECURITY_ERROR. For more
information about event listeners and event handlers, see Chapter 13, “Handling Events,” on
page 345.
Error events fit into one of two categories:
■ Error events that extend the ErrorEvent class
The flash.events.ErrorEvent class contains the properties and methods for managing Flash
Player run-time errors related to networking and communication operations. The
AsyncErrorEvent, IOErrorEvent, and SecurityErrorEvent classes extend the ErrorEvent
class. If you’re using the debugger version of Flash Player, a dialog box will inform you at
run-time of any error events without listener functions that the player encounters.
NOTE
If you want to override the Error.toString() method in your subclass, you need to give it
one
...(rest) parameter. The ECMAScript (ECMA-262) edition 3 language
specification defines the
Error.toString() method that way, and ActionScript 3.0
defines it the same way for backward compatibility with that specification. Therefore,
when you override the
Error.toString() method, you must match the parameters
exactly. You will not want to pass any parameters to your
toString() method at run time,
because those parameters are ignored.