The error classes are utterly boring except for the wrinkle that the
predefined subclasses of Error -- EvalError, RangeError, and so on --
all have a [[Class]] that is "Error", not their natural class name.
Anyhow, the draft is enclosed.

Unlike the ES3 spec, I've expanded the subclasses of Error into
individual sections, because I always felt like I had to do a mental
instantiation of what I was reading when I was reading these sections in
the ES3 spec.  (On the other hand, the spec is maybe a percent larger
with the expansion.)

--lars
Title: Error classes

Error classes


NAME:                       "Error classes"
FILE:                       spec/library/Error.html
CATEGORY:                   Pre-defined classes
SOURCES:                    REFERENCE [1]
SPEC AUTHOR:                Lars
DRAFT STATUS:               DRAFT 1 - 2008-03-06
REVIEWED AGAINST ES3:       YES
REVIEWED AGAINST ERRATA:    YES
REVIEWED AGAINST BASE DOC:  YES
REVIEWED AGAINST PROPOSALS: YES
REVIEWED AGAINST CODE:      YES
REVIEWS:                    (none)
IMPLEMENTATION STATUS:      ES4 RI

NOTES

  * Due to a bug [2] in the reference implementation, the private
    methods in the error classes are currently in the namespace
    "Private", not in "private".  This will be changed eventually.

REFERENCES

[1] ECMAScript 3rd Edition Specification
[2] http://bugs.ecmascript.org/ticket/368


ECMAScript provides a hierarchy of standard pre-defined error classes rooted at the class Error (see class Error).

The ECMAScript implementation throws a new instance of one of the pre-defined error classes when it detects certain run-time errors. The conditions under which run-time errors are detected are explained throughout this Standard. The description of each of the pre-defined error classes contains a summary of the conditions under which an instance of that particular error class is thrown.

The class Error serves as the base class for all the classes describing standard errors thrown by the ECMAScript implementation: EvalError, RangeError, ReferenceError, SyntaxError, TypeError, and URIError. (See class EvalError, class RangeError, class ReferenceError, class SyntaxError, class TypeError, class URIError.)

The class Error as well as all its pre-defined subclasses are non-final and dynamic and may be subclassed by user-defined exception classes.

All the pre-defined subclasses of Error share the same structure.

The class Error

The class Error is a dynamic, non-final subclass of Object. Instances of Error are not thrown by the implementation; rather, Error is intended to serve as a base class for other error classes whose instances represent specific classes of run-time errors.

Synopsis

The class Error provides the following interface:

dynamic class Error extends Object 
{
    public function Error(message) …
    static meta function invoke(message) …
    
    static public const length = 1
    
    override intrinsic function toString() …
    override helper function getClassName() …
}

The Error prototype object provides these direct properties:

    toString: function () …
    name:     "Error"
    message:  …

Methods on the Error class

new Error (message)

Description

When the Error constructor is called as part of a new Error _expression_ it initialises the newly created object: If message is not undefined, the dynamic message property of the newly constructed Error object is set to string(message).

Implementation

public function Error(message) {
    if (message !== undefined)
        this.message = string(message);
}

Error (message)

Description

When the Error class object is called as a function, it creates and initialises a new Error object by invoking the Error constructor.

Returns

The Error class object called as a function returns a new Error object.

Implementation

static meta function invoke(message)
    new Error(message);

Methods on Error instances

intrinsic::toString ( )

Description

The intrinsic toString method converts the Error object to an implementation-defined string.

Returns

A string object.

Implementation

override intrinsic function toString()
    Private::toString();

The private function toString is implementation-defined.

helper::getClassName ( )

Description

The helper method getClassName overrides the method defined in Object and makes the pre-defined subclasses of Error appear to have the [[Class]] value "Error".

NOTE   The helper method getClassName is a specification artifact. The protocol it defines for overriding [[Class]] is not available to user code.

Returns

The helper method getClassName returns a string.

Implementation

override helper function getClassName() {
    if (helper::isExactlyType(this, EvalError) ||
        helper::isExactlyType(this, RangeError) ||
        helper::isExactlyType(this, ReferenceError) ||
        helper::isExactlyType(this, SyntaxError) ||
        helper::isExactlyType(this, TypeError) ||
        helper::isExactlyType(this, URIError))
        return "Error";
    return super.helper::getClassName();
}

helper function isExactlyType(obj, cls)
    let (objtype = reflect::typeOf(obj))
        cls.reflect::isSubtypeOf(objtype) && objtype.reflect::isSubtypeOf(cls);

Methods on the Error prototype object

toString ( )

Description

The prototype toString method calls the private toString method.

Returns

The prototype toString method returns a string object.

Implementation

prototype function toString(this: Error)
    this.Private::toString();

Value properties on the Error prototype object

name

The initial value of the name prototype property is the string "Error".

message

The initial value of the message prototype property is an implementation-defined string.

The class EvalError

The implementation throws a new EvalError instance when it detects that the global function eval was used in a way that is incompatible with its definition. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

The EvalError class provides this interface:

dynamic class EvalError extends Error
{
    public function EvalError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The EvalError prototype object provides these direct properties:

    name:    "EvalError"
    message: …

Methods on the EvalError class

new EvalError (message)

Description

When the EvalError constructor is called as part of a new EvalError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function EvalError(message)
    : super(message)
{
}

EvalError (message)

Description

When the EvalError class object is called as a function, it creates and initialises a new EvalError object by invoking the EvalError constructor.

Returns

The EvalError class object called as a function returns a new EvalError object.

Implementation

static meta function invoke(message)
    new EvalError(message);

Value properties on the EvalError prototype object

name

The initial value of the name prototype property is the string "EvalError".

message

The initial value of the message prototype property is an implementation-defined string.

The class RangeError

The implementation throws a new RangeError instance when it detects that a numeric value has exceeded the allowable range. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

The RangeError class provides this interface:

dynamic class RangeError extends Error
{
    public function RangeError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The RangeError prototype object provides these direct properties:

    name:    "RangeError"
    message: …

Methods on the RangeError class

new RangeError (message)

Description

When the RangeError constructor is called as part of a new RangeError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function RangeError(message)
    : super(message)
{
}

RangeError (message)

Description

When the RangeError class object is called as a function, it creates and initialises a new RangeError object by invoking the RangeError constructor.

Returns

The RangeError class object called as a function returns a new RangeError object.

Implementation

static meta function invoke(message)
    new RangeError(message);

Value properties on the RangeError prototype object

name

The initial value of the name prototype property is the string "RangeError".

message

The initial value of the message prototype property is an implementation-defined string.

The class ReferenceError

The implementation throws a new ReferenceError instance when it detects an invalid reference value. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

dynamic class ReferenceError extends Error
{
    public function ReferenceError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The ReferenceError prototype object provides these direct properties:

    name:    "ReferenceError"
    message: …

Methods on the ReferenceError class

new ReferenceError (message)

Description

When the ReferenceError constructor is called as part of a new ReferenceError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function ReferenceError(message)
    : super(message)
{
}

ReferenceError (message)

Description

When the ReferenceError class object is called as a function, it creates and initialises a new ReferenceError object by invoking the ReferenceError constructor.

Returns

The ReferenceError class object called as a function returns a new ReferenceError object.

Implementation

static meta function invoke(message)
    new ReferenceError(message);

Value properties on the ReferenceError prototype object

name

The initial value of the name prototype property is the string "ReferenceError".

message

The initial value of the message prototype property is an implementation-defined string.

The class SyntaxError

The implementation throws a new SyntaxError instance when a parsing error has occurred. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

dynamic class SyntaxError extends Error
{
    public function SyntaxError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The SyntaxError prototype object provides these direct properties:

    name:    "SyntaxError"
    message: …

Methods on the SyntaxError class

new SyntaxError (message)

Description

When the SyntaxError constructor is called as part of a new SyntaxError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function SyntaxError(message)
    : super(message)
{
}

SyntaxError (message)

Description

When the SyntaxError class object is called as a function, it creates and initialises a new SyntaxError object by invoking the SyntaxError constructor.

Returns

The SyntaxError class object called as a function returns a new SyntaxError object.

Implementation

static meta function invoke(message)
    new SyntaxError(message);

Value properties on the SyntaxError prototype object

name

The initial value of the name prototype property is the string "SyntaxError".

message

The initial value of the message prototype property is an implementation-defined string.

The class TypeError

The implementation throws a new TypeError instance when it has detected that the actual type of an operand is different than the expected type. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

dynamic class TypeError extends Error
{
    public function TypeError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The TypeError prototype object provides these direct properties:

    name:    "TypeError"
    message: …

Methods on the TypeError class

new TypeError (message)

Description

When the TypeError constructor is called as part of a new TypeError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function TypeError(message)
    : super(message)
{
}

TypeError (message)

Description

When the TypeError class object is called as a function, it creates and initialises a new TypeError object by invoking the TypeError constructor.

Returns

The TypeError class object called as a function returns a new TypeError object.

Implementation

static meta function invoke(message)
    new TypeError(message);

Value properties on the TypeError prototype object

name

The initial value of the name prototype property is the string "TypeError".

message

The initial value of the message prototype property is an implementation-defined string.

The class URIError

The implementation throws a new URIError when one of the global URI handling functions was used in a way that is incompatible with its definition. See sections XXX.

FIXME   Clean up the section references when we reach final draft.

Synopsis

dynamic class URIError extends Error
{
    public function URIError(message) …
    static meta function invoke(message) …
    
    static public const length = 1
}

The URIError prototype object provides these direct properties:

    name:    "URIError"
    message: …

Methods on the URIError class

new URIError (message)

Description

When the URIError constructor is called as part of a new URIError _expression_ it initialises the newly created object by delegating to the Error constructor.

Implementation

public function URIError(message)
    : super(message)
{
}

URIError (message)

Description

When the URIError class object is called as a function, it creates and initialises a new URIError object by invoking the URIError constructor.

Returns

The URIError class object called as a function returns a new URIError object.

Implementation

static meta function invoke(message)
    new URIError(message);

Value properties on the URIError prototype object

name

The initial value of the name prototype property is the string "URIError".

message

The initial value of the message prototype property is an implementation-defined string.

_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to