ECMAScript Language Specification

Standard ECMA-262 3rd Edition -December 1999

16 Errors

An implementation should report runtime errors at the time the relevant language construct is evaluated. An implementation may report syntax errors in the program at the time the program is read in, or it may, at its option, defer reporting syntax errors until the relevant statement is reached. An implementation may report syntax errors in eval code at the time eval is called, or it may, at its option, defer reporting syntax errors until the relevant statement is reached.

An implementation may treat any instance of the following kinds of runtime errors as a syntax error and therefore report it early:

  • Improper uses of return, break, and continue.
  • Using the eval property other than via a direct call.
  • Errors in regular expression literals.
  • Attempts to call PutValue on a value that is not a reference (for example, executing the assignment statement 3= 4).

An implementation shall not report other kinds of runtime errors early even if the compiler can prove that a construct cannot execute without error under any circumstances. An implementation may issue an early warning in such a case, but it should not report the error until the relevant construct is actually executed.

An implementation shall report all errors as specified, except for the following:

  • An implementation may extend program and regular expression syntax. To permit this, all operations (such as calling eval, using a regular expression literal, or using the Function or RegExp constructor) that are allowed to throw SyntaxError are permitted to exhibit implementation-defined behaviour instead of throwing SyntaxError when they encounter an implementation-defined extension to the program or regular expression syntax.
  • An implementation may provide additional types, values, objects, properties, and functions beyond those described in this specification. This may cause constructs (such as looking up a variable in the global scope) to have implementation-defined behaviour instead of throwing an error (such as ReferenceError).
  • An implementation is not required to detect EvalError. If it chooses not to detect EvalError, the implementation must allow eval to be used indirectly and/ or allow assignments to eval.
  • An implementation may define behaviour other than throwing RangeError for toFixed, toExponential, and toPrecision when the fractionDigits or precision argument is outside the specified range.