JavaScript Tutorial: Error objects
[this page | pdf | back links]
JavaScript
error objects are used by the try … catch …
finally and throw
statements to implement structured error handling.
Error objects support the
following properties and methods. Note, some browser suppliers e.g. Microsoft
have additional non-standard properties such as .description,
which seems otherwise to be the same as .message
but will not be recognised by non-Microsoft browsers (so should be avoided if
users are likely to use other browsers to view the relevant webpage).
Properties:
Property
|
Description
|
More
|
constructor
|
Returns object’s
constructor function
|
Here
|
message
|
Returns a string
containing the error message associated with the error
|
Here
|
name
|
Returns the name (i.e. exception type) of an error
|
Here
|
number
|
Sets / returns numeric
value associated with error
|
Here
|
prototype
|
Allows author to add
properties and methods to an object
|
Here
|
stack
|
Gets trace information regarding the error and is added to
when an error is raised, and is updated repeatedly if the error is raised
multiple times
|
Here
|
stackTraceLimit
|
(Default 10). Sets /
returns stack trace limit, i.e. number of error frames displayed in stack
|
Here
|
Methods:
Method
|
Description
|
More
|
toString()
|
Returns the (string) value
of an error object
|
Here
|
valueOf()
|
Returns the primitive
value of an object
|
Here
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Error Objects