| Package | Top Level |
| Class | public dynamic class Error |
| Inheritance | Error Object |
| Subclasses | ArgumentError, DefinitionError, EvalError, IllegalOperationError, InvalidSWFError, IOError, MemoryError, RangeError, ReferenceError, ScriptTimeoutError, SecurityError, StackOverflowError, SyntaxError, TypeError, URIError, VerifyError |
Error constructor function.
Typically, you throw a new Error object from within a try
code block that is then caught by a catch or finally code block.
You can also create a subclass of the Error class and throw instances of that subclass.
View the examples.| Property | Defined by | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
| message : String
Contains the message associated with the Error object.
| Error | ||
| name : String
Contains the name of the Error object.
| Error | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| Function | Defined by | ||
|---|---|---|---|
|
Creates a new Error object.
| Error | ||
|
For debugger versions of the Flash Player, only; this method returns the call stack for an error
as a string at the time of the error's construction.
| Error | ||
![]() |
Indicates whether an object has a specified property defined.
| Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
![]() |
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
Sets the availability of a dynamic property for loop operations.
| Object | |
|
Returns the string "Error" by default or the value contained in Error.message, if defined.
| Error | ||
![]() |
Returns the primitive value of the specified object.
| Object | |
public var message:String
Error". You can specify a message property when you create an
Error object by passing the error string to the Error constructor function.
See also
| statements.html#throw, statements.html#try..catch..finally |
public var name:String
Error".
See also
| statements.html#throw, statements.html#try..catch..finally |
public function Error(message:String = "")
message is specified, its value is assigned
to the object's Error.message property.
Parameters
message:String (default = "") — A string associated with the Error object; this parameter
is optional.
|
err and then, using the
Error() constructor, assigns the string New Error Message to
err.
var err:Error = new Error();
trace(err.toString()); // Error
err = new Error("New Error Message");
trace(err.toString()); // Error: New Error Message
| statements.html#throw, statements.html#try..catch..finally |
public function getStackTrace():String
TypeError: null cannot be converted to an object
at com.xyz.OrderEntry.retrieveData(OrderEntry.as:995)
at com.xyz.OrderEntry.init(OrderEntry.as:200)
at com.xyz.OrderEntry.$construct(OrderEntry.as:148)
String —
A string representation of the call stack.
|
public override function toString():String
String —
The error message.
|
err and then, using the
Error() constructor, assigns the string New Error Message to
err. Lastly the message property is set to Another New Error Message,
which overwrites New Error Message.
Notice how the toString() method is explicitally called within each trace()
statement. Although this is not normally required, it is recommended regardless.
var err:Error = new Error();
trace(err.toString()); // Error
err = new Error("New Error Message");
trace(err.toString()); // Error: New Error Message
err.message = "Another New Error Message";
trace(err.toString()); // Error: Another New Error Message
| Error.message, statements.html#throw, statements.html#try..catch..finally |
ErrorExample to show
how a custom error can be generated. This is accomplished using the following
steps:
nullArray of type Array is declared, but notice
a new Array object is never created.push() method within an error handling code segment that catches a
custom error using the CustomError class, which extends Error.
package {
import flash.display.Sprite;
public class ErrorExample extends Sprite {
private var nullArray:Array;
public function ErrorExample() {
try {
nullArray.push("item");
}
catch(e:Error) {
throw new CustomError("nullArray is null");
}
}
}
}
class CustomError extends Error {
public var name:String = "CustomError";
public function CustomError(message:String) {
super(message);
}
}