Exception (Definition)

An unexpected result from an expression evaluation.

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:

ValueNameDOM
1INDEX_SIZE_ERR1
2DOMSTRING_SIZE_ERR1
3HIERARCHY_REQUEST_ERR1
4WRONG_DOCUMENT_ERR1
5INVALID_CHARACTER_ERR1
6NO_DATA_ALLOWED_ERR1
7NO_MODIFICATION_ALLOWED_ERR1
8NOT_FOUND_ERR1
9NOT_SUPPORTED_ERR1
10INUSE_ATTRIBUTE_ERR1
11INVALID_STATE_ERR2
12SYNTAX_ERR2
13INVALID_MODIFICATION_ERR2
14NAMESPACE_ERR2
15INVALID_ACCESS_ERR2

See also:Expression, Infinity, NaN, undefined