The TRY statement tests the code block for errors.
The catch statement handles the error.
The throw statement creates a custom error.
Errors are bound to occur, and when the JavaScript engine executes JavaScript code, various errors occur: it can be a syntax error, usually a coding error or typos caused by a programmer. It may be a misspelling or a missing feature in the language (possibly due to browser differences), possibly due to error output from the server or user. Of course, it may also be due to many other unpredictable factors. When an error occurs, the JavaScript engine usually stops and generates an error message when something goes wrong. The technical term that describes this situation is that JavaScript throws an error. The Try statement allows us to define a block of code that performs error testing at execution time. The catch statement allows us to define a block of code that executes when a try block of code has an error. The JavaScript statement try and catch are paired occurrences.
Here is an example of the explanation:
<! DOCTYPE html>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
JavaScript base 1:javascript Errors-Throw, Try, and Catch