flex 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:
- To identify specific errors or groups of errors that are unique to your application.
For example, you may want to take different actions for errors thrown by your own code, in addition to those trapped by Flash Player or Adobe AIR. You can create a subclass of the Error class to track the new error data type in try..catch blocks.
- To provide unique error display capabilities for errors generated by your application.
For example, you can create a new toString() method that formats your error messages in a certain way. You can also define a lookupErrorString() method that takes an error code and retrieves the proper message based on the user's language preference.
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)
}
11:18 AM
|
Labels:
Flex Action Script 3.0,
Flex Samples
|
This entry was posted on 11:18 AM
and is filed under
Flex Action Script 3.0
,
Flex Samples
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 comments:
Post a Comment