Package | Top Level |
Class | public dynamic class Error |
Inheritance | Error ![]() |
Subclasses | ArgumentError, AutomationError, CollectionViewError, CursorError, DefinitionError, DRMManagerError, EvalError, Fault, IllegalOperationError, InvalidCategoryError, InvalidFilterError, InvalidSWFError, IOError, ItemPendingError, MemoryError, MessagingError, RangeError, ReferenceError, ScriptTimeoutError, SecurityError, SortError, SQLError, StackOverflowError, SyntaxError, TypeError, URIError, VerifyError, VideoError |
Error
constructor function.
Typically, you throw a new Error object from within a try
code block that is caught by a catch
or finally
code block.
You can also create a subclass of the Error class and throw instances of that subclass.
See also
Property | Defined By | ||
---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | |
errorID : int [read-only]
Contains the reference number associated with the specific error message. | Error | ||
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 |
Method | Defined By | ||
---|---|---|---|
Creates a new Error object. | Error | ||
Returns the call stack for an error as a string at the time of the error's construction (for the debugger version
of Flash Player and the AIR Debug Launcher (ADL) only; returns null if not using the debugger version
of Flash Player or the ADL. | 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 representation of this object, formatted according to locale-specific conventions. | Object | |
[override]
Returns the string "Error" by default or the value contained in the Error.message property,
if defined. | Error | ||
![]() |
Returns the primitive value of the specified object. | Object |
errorID | property |
errorID:int
[read-only]
Contains the reference number associated with the specific error message. For a custom Error object,
this number is the value from the id
parameter supplied in the constructor.
public function get errorID():int
message | property |
public var message:String
Contains the message associated with the Error object. By default, the value of this property
is "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
name | property |
public var name:String
Contains the name of the Error object. By default, the value of this property is "Error
".
See also
Error | () | Constructor |
public function Error(message:String = "", id:int = 0)
Creates a new Error object. If message
is specified, its value is assigned
to the object's Error.message
property.
message:String (default = " ") — A string associated with the Error object; this parameter
is optional.
| |
id:int (default = 0 ) — A reference number to associate with the specific error message.
|
See also
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
getStackTrace | () | method |
public function getStackTrace():String
Returns the call stack for an error as a string at the time of the error's construction (for the debugger version
of Flash Player and the AIR Debug Launcher (ADL) only; returns null
if not using the debugger version
of Flash Player or the ADL. As shown in the following example, the first line of the return value is the
string representation of the exception object, followed by the stack trace elements:
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.
|
toString | () | method |
override public function toString():String
Returns the string "Error"
by default or the value contained in the Error.message
property,
if defined.
String — The error message.
|
See also
err
and then, using the
Error()
constructor, assigns the string "New Error Message"
to
err
. Finally, the message
property is set to "Another New Error Message"
,
which overwrites "New Error Message"
.
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
ErrorExample
class to show
how a custom error can be generated. This is accomplished with the following
steps:
nullArray
of Array type is declared, but notice
that a new Array object is never created.push()
method within an error handling code segment that catches a
custom error by using the CustomError
class, which extends Error
.trace()
statement. 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 function CustomError(message:String) { super(message); } }