An exception occurs when an expression yields a result that was not expected when you evaluate it. In numerical expressions, the NaN value is provided for just such a circumstance. NaN represents a numeric quantity that cannot be resolved within the range of meaningful values. The interpreter knows it is numeric but the value is wrong. The undefined and Infinity values also help in the management of such exceptions.
In general, the exception handling in JavaScript is better than that in a compiled language and therefore it is more forgiving. Its best efforts will usually be good enough to yield a working script where a compiled program may fail with a fatal error.
The DOM level 1 specification describes an enumerated set of exception codes as follows:
Value | Name | DOM |
---|---|---|
1 | INDEX_SIZE_ERR | 1 |
2 | DOMSTRING_SIZE_ERR | 1 |
3 | HIERARCHY_REQUEST_ERR | 1 |
4 | WRONG_DOCUMENT_ERR | 1 |
5 | INVALID_CHARACTER_ERR | 1 |
6 | NO_DATA_ALLOWED_ERR | 1 |
7 | NO_MODIFICATION_ALLOWED_ERR | 1 |
8 | NOT_FOUND_ERR | 1 |
9 | NOT_SUPPORTED_ERR | 1 |
10 | INUSE_ATTRIBUTE_ERR | 1 |
11 | INVALID_STATE_ERR | 2 |
12 | SYNTAX_ERR | 2 |
13 | INVALID_MODIFICATION_ERR | 2 |
14 | NAMESPACE_ERR | 2 |
15 | INVALID_ACCESS_ERR | 2 |
See also: | Expression, Infinity, NaN, undefined |
Prev | Home | Next |
Exactly equal to (===) | Up | Exception handling |
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. |