Javascript - Exception

> (World Wide) Web - (W3|WWW) > Javascript (Js|ECMAScript) > ECMAScript - Grammar Standard

1 - About

exception in Javascript

Exception can be catched:

  • in a try, catch, throw, finally statement.
  • with the catch function with a promise. See catch

2 - Management

2.1 - Pause

2.2 - Caught exception variable scope

The try…catch binds a caught exception to a variable that is scoped just to the catch block (not on the function level). This is the only scope exception.

var foo = "initial value";
try {
	throw "exception";
} catch (foo) { //  < -- The local variable foo is a caught exception and will not affect the local variable because its scope is limited to the try catch block
	foo = "exception"; // <-- This change is only for the try block
console.log("The foo variable was not polluted when declared as a caught exception\n"+
  "foo will still have its initial value");


2.3 - Caugth with Google Analytics

web/javascript/es/exception.txt · Last modified: 2019/04/10 21:33 by gerardnico