| Availability: |
| ||||||
| JavaScript syntax: | - | myError = new Error() | |||||
| - | myError = new Error(aNumber) | ||||||
| - | myError = new Error(aNumber, aText) | ||||||
| Argument list: | aNumber | An error number | |||||
| aText | A text describing the error | ||||||
| Object properties: | constructor, description, message, name, number, prototype | ||||||
| Object methods: | toString() | ||||||
This object is provided to create custom error codes for your application. The ECMA standard (edition 3) describes them as objects that are thrown as exceptions when a run-time error occurs.
These objects are passed as the first argument of the catch() function in a try ... catch structure where you can inspect them and deal with the error.
// Force an error condition
myError = new Error(100, "My user defined error text")
try
{
throw myError;
}
catch(anErr)
{
confirm(anErr.description);
}
finally
{
alert("Sorted");
}| Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
|---|---|---|---|---|---|---|---|---|---|---|---|
| constructor | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | DontEnum |
| description | ![]() | 5.0 ![]() | ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| message | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | ![]() |
| name | 1.5 ![]() | 5.5 ![]() | 6.0 ![]() | 5.5 ![]() | ![]() | ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
| number | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
| prototype | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | 3.0 ![]() | 2.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | ReadOnly, DontDelete, DontEnum |
| Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
|---|---|---|---|---|---|---|---|---|---|---|---|
| toString() | 1.5 ![]() | 5.0 ![]() | 6.0 ![]() | 5.0 ![]() | 3.0 ![]() | 2.0 ![]() | 3 ![]() | ![]() | ![]() | ![]() | - |
ECMA 262 edition 3 - section - 15.1.4.9
ECMA 262 edition 3 - section - 15.11.1
ECMA 262 edition 3 - section - 15.11.2
| Prev | Home | Next |
| Error handling | Up | Error() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||