ActionScript 3.0 includes many tools for error handling, including:
- Error classes. In compliance with the ECMAScript (ECMA-262) edition 4 draft language specification, ActionScript 3.0 includes a broad range of Error classes to expand the scope of situations that may produce error objects. Each Error class helps applications handle and respond to specific error conditions, whether they are related to system errors (like a MemoryError condition), coding errors (like an ArgumentError condition), networking and communication errors (like a URIError condition), or other situations. For more information on each class, see Comparing the Error classes.
- Fewer silent failures. In earlier versions of Flash Player, errors were generated and reported only if you explicitly used the throw statement. For Flash Player 9 and Adobe AIR, native ActionScript methods and properties throw run-time errors that allow you to handle these exceptions more effectively when they occur, and then individually react to each exception.
- Clear error messages displayed during debugging. When you are using the debugger version of Flash Player or Adobe AIR, problematic code or situations will generate robust error messages, which help you easily identify reasons why a particular block of code fails. This makes fixing errors more efficient. For more information, see Working with the debugger versions of Flash Player and AIR.
- Precise errors allow for clear error messages displayed to users at run time. In previous versions of Flash Player, the FileReference.upload() method returned a Boolean value of false if the upload() call was unsuccessful, indicating one of five possible errors. If an error occurs when you call the upload() method in ActionScript 3.0, you can throw one of four specific errors, which helps you display more accurate error messages to end users.
- Refined error handling. Distinct errors are thrown for many common situations. For example, in ActionScript 2.0, before a FileReference object has been populated, the name property has the value null (so, before you can use or display the name property, you need to ensure that the value is set and not null). In ActionScript 3.0, if you attempt to access the name property before it has been populated, Flash Player or AIR throws an IllegalOperationError, which informs you that the value has not been set, and you can use try..catch..finally blocks to handle the error. For more information see Using try..catch..finally statements.
- No significant performance drawbacks. Using try..catch..finally blocks to handle errors takes little or no additional resources compared to previous versions of ActionScript.
- An ErrorEvent class that allows you to build listeners for specific asynchronous error events. For more information see Responding to error events and status.