Multiple catch clauses

In JavaScript, try/catch statements are use to handle exceptions present in the try code blocks.

The try clause

In the try block, the statements to be evaluated are executed.

Tip

If you want to deliberately throw an exception, we would use the throw statement. This will abort the execution of the remaining statements, and the control will move to the catch block.

The catch clause

After checking and encountering an error in the statements in the try block, the exception block is called. If the exception encountered is the same as the exception handled in the catch block, then the control immediately shifts to the catch block, and the statements within the catch block are executed.

The statements presented after the erroneous statement ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.