Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

JavaScript/Reserved words/throw

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

JavaScript this throws Reserved words 0 The throw keyword The throw keyword is used to be sure that an exception is caught when it occurs. It has the obligatory catch clause, and the optional finally clause. If the code inside the try block does not cause an exception, the code inside the finally block will execute, if it exists. If an error occurs, the comments inside the catch clause will execute, the finally block will execute, if it exists. Examples The code var result; try { result = log(-12.05); alert("Executed comment successfully."); } catch(err) { document.getElementById("demo").innerHTML = err.message; throw("An error occurred, and result could not be calculated!"); } finally { alert("result = " + result); // This line will execute anyway } (An exception with the text "An error occurred, and result could not be calculated!" will be thrown. result = undefined See also catch finally try JavaScript this throws Reserved words 0