Creating custom error classes

You can extend one of the standard Error classes to create your own specialized error classes in ActionScript. There are a number of reasons to create your own error classes:

A specialized error class must extend the core ActionScript Error class. Here is an example of a specialized AppError class that extends the Error class:

public class AppError extends Error
{
    public function AppError(message:String, errorID:int)
    {
        super(message, errorID);
    }
}

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)
}

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.


Flash CS3


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000103.html