Skip to main content

Comparing the Error classes

ActionScript provides a number of predefined Error classes. But, you can also use the same Error classes in your own code. There are two main types of Error classes in ActionScript 3.0: ActionScript core Error classes and flash.error package Error classes. The flash.error package contains additional classes to aid ActionScript 3.0 application development and debugging.

Core Error classes

The core error classes include the Error, ArgumentError, EvalError, RangeError, ReferenceError, SecurityError, SyntaxError, TypeError, URIError, and VerifyError classes. Each of these classes are located in the top-level namespace.

Class name

Description

Notes

Error

The Error class is for throwing exceptions, and is the base class for the other exception classes defined in ECMAScript: EvalError, RangeError, ReferenceError, SyntaxError, TypeError, and URIError.

The Error class serves as the base class for all run-time errors, and is the recommended base class for any custom error classes.

ArgumentError

The ArgumentError class represents an error that occurs when the parameter values supplied during a function call do not match the parameters defined for that function.

Some examples of argument errors include the following:

  • Too few or too many arguments are supplied to a method.

  • An argument was expected to be a member of an enumeration and was not.

EvalError

An EvalError exception is thrown if any parameters are passed to the Function class's constructor or if user code calls theeval()function.

In ActionScript 3.0, support for theeval() function has been removed and attempts to use the function result in an error.

Earlier versions of Flash Player used theeval() function to access variables, properties, objects, or movie clips by name.

RangeError

A RangeError exception is thrown if a numeric value falls outside an acceptable range.

For example, a RangeError is thrown by the Timer class if a delay was either negative or was not finite. A RangeError could also be thrown if you attempted to add a display object at an invalid depth.

ReferenceError

A ReferenceError exception is thrown when a reference to an undefined property is attempted on a sealed (nondynamic) object. Versions of the ActionScript compiler before ActionScript 3.0 did not throw an error when access was attempted to a property that wasundefined. However ActionScript 3.0 throws the ReferenceError exception in this condition.

Exceptions for undefined variables point to potential bugs, helping you improve software quality. However, if you are not used to having to initialize your variables, this new ActionScript behavior requires some changes in your coding habits.

SecurityError

The SecurityError exception is thrown when a security violation takes place and access is denied.

Some examples of security errors include the following:

  • An unauthorized property access or method call is made across a security sandbox boundary.

  • An attempt was made to access a URL not permitted by the security sandbox.

  • A socket connection was attempted to a port but the necessary socket policy file wasn't present.

  • An attempt was made to access the user's camera or microphone, and the user denide the access to the device.

SyntaxError

A SyntaxError exception is thrown when a parsing error occurs in your ActionScript code.

A SyntaxError can be thrown under the following circumstances:

  • ActionScript throws SyntaxError exceptions when the RegExp class parses an invalid regular expression.

  • ActionScript throws SyntaxError exceptions when the XMLDocument class parses invalid XML.

TypeError

The TypeError exception is thrown when the actual type of an operand is different from the expected type.

A TypeError can be thrown under the following circumstances:

  • An actual parameter of a function or method could not be coerced to the formal parameter type.

  • A value is assigned to a variable and cannot be coerced to the variable's type.

  • The right side of theis orinstanceofoperator is not a valid type.

  • Thesuper keyword is used illegally.

  • A property lookup results in more than one binding, and is therefore ambiguous.

  • A method is called on an incompatible object. For example, a TypeError exception is thrown if a method in the RegExp class is "grafted" onto a generic object and then called.

URIError

The URIError exception is thrown when one of the global URI handling functions is used in a way that is incompatible with its definition.

A URIError can be thrown under the following circumstances:

An invalid URI is specified for a Flash Player API function that expects a valid URI, such asSocket.connect().

VerifyError

A VerifyError exception is thrown when a malformed or corrupted SWF file is encountered.

When a SWF file loads another SWF file, the parent SWF file can catch a VerifyError generated by the loaded SWF file.

flash.error package Error classes

The flash.error package contains Error classes that are considered part of the Flash runtime API. In contrast to the Error classes described, the flash.error package communicates errors events that are specific to Flash runtimes (such as Flash Player and Adobe AIR).

Class name

Description

Notes

EOFError

An EOFError exception is thrown when you attempt to read past the end of the available data.

For example, an EOFError is thrown when one of the read methods in the IDataInput interface is called and there is insufficient data to satisfy the read request.

IllegalOperationError

An IllegalOperationError exception is thrown when a method is not implemented or the implementation doesn't cover the current usage.

Examples of illegal operation error exceptions include the following:

  • A base class, such as DisplayObjectContainer, provides more functionality than the Stage can support. For example, if you attempt to get or set a mask on the Stage (usingstage.mask), the Flash runtime throws an IllegalOperationError with the message "The Stage class does not implement this property or method."

  • A subclass inherits a method it does not require and does not want to support.

  • Certain accessibility methods are called when Flash Player is compiled without accessibility support.

  • Authoring-only features are called from a run-time version of Flash Player.

  • You attempt to set the name of an object placed on the timeline.

IOError

An IOError exception is thrown when some type of I/O exception occurs.

You get this error, for example, when a read-write operation is attempted on a socket that is not connected or that has become disconnected.

MemoryError

A MemoryError exception is thrown when a memory allocation request fails.

By default, ActionScript Virtual Machine 2 does not impose a limit on how much memory an ActionScript program allocates. On a desktop system, memory allocation failures are infrequent. You see an error thrown when the system is unable to allocate the memory required for an operation. So, on a desktop system, this exception is rare unless an allocation request is extremely large; for example, a request for 3 billion bytes is impossible because a 32-bit Microsoft® Windows® program can access only 2 GB of address space.

ScriptTimeoutError

A ScriptTimeoutError exception is thrown when a script timeout interval of 15 seconds is reached. By catching a ScriptTimeoutError exception, you can handle the script timeout more gracefully. If there is no exception handler, the uncaught exception handler displays a dialog box with an error message.

To prevent a malicious developer from catching the exception and staying in an infinite loop, only the first ScriptTimeoutError exception thrown in the course of a particular script can be caught. A subsequent ScriptTimeoutError exception cannot be caught by your code and immediately goes to the uncaught exception handler.

StackOverflowError

The StackOverflowError exception is thrown when the stack available to the script has been exhausted.

A StackOverflowError exception might indicate that infinite recursion has occurred.