How to catch exceptions in JavaScript?

To catch exceptions in JavaScript, use try?catch?finally. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions.

You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors.

Example

You can try to run the following code to learn how to catch exceptions in JavaScript ?

   
      
   

   
      

Click the following to see the result:

     
               
   
Updated on: 2026-03-11T22:50:41+05:30

389 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements