Applications are created to handle many different conditions affected by the system itself and outside players. Error handling allows applications to define the normal flow of execution and act upon exceptions.
Error Types
To understand the breadth of error handling, an outline of the error types and their functions is explored. The two main types of errors are compile-time and run-time errors. The Flash Player historically is capable of both synchronous and asynchronous method calls. There are ways to handle errors in both situations. Then, finally, the act of not catching errors is also considered a method of error handling.
Compile-time Errors
Because ActionScript 3.0 defines a more strongly typed language, the depth of compile-time exception and error handling is far greater than previous versions of ActionScript. The compile-time errors are reported when the mxmlc compiler is called and usually refer to syntax problems in the application. Some common compile-time errors can be explored by using the SortedMap class from
package
{
// comment out import line
// import flash.utils.Dictionary;
public class SortedMap
{
// Declaring Dictionary class
private var map:Dictionary;
private var keys:Array;
public function SortedMap()
{
map = new Dictionary();
keys = new Array();
}
...
...
}
This will throw a compile-time error with the code value of 1046 and message of “Type was not found or was not a compile-time constant: Dictionary.” Each class file must import class definitions before the class can be declared or instantiated. Here is another compile-time error example:
package
{
import flash.utils.Dictionary;
public class SortedMap
{
private var map:Dictionary;
private var keys:Array;
public function SortedMap()
{
map = new Dictionary();
// Assign map to keys, different types
keys = map;
}
...
...
}
This will throw a compile-time error with the code value of 1067 and message of “Implicit coercion of a value of type flash.utils:Dictionary to an unrelated type Array.” Here is another compile-time error example:
var sortedMap:SortedMap = new SortedMap(); sortedMap.addItem( user1 );
This will throw a compile-time error with the code value of 1136 and message of “Incorrect number of arguments. Expected 2.” You can find a list of compile-time errors in the Adobe Flex 2 language reference documentation.







