This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

throw

Summary

Generates an error condition that can be handled by a try…catch…finally statement.

Syntax

throw exception

Examples

The following example throws an error inside a try block, and it is caught in the catch block.

try {
         throw new Error(200, "x equals zero");
 }
 catch (e) {
     document.write(e.message);
 }

 // Output: x equals zero.

Remarks

The required exception argument can be any expression.

See also

Other articles

Attributions

  • Microsoft Developer Network: Article