JavaScript Error Handling

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • try { … } catch (error) { … }
  • try { … } finally { … }
  • try { … } catch (error) { … } finally { … }
  • throw new Error([message]);
  • throw Error([message]);

Remarks

try allows you to define a block of code to be tested for errors while it is being executed.

catch allows you to define a block of code to be executed, if an error occurs in the try block.

finally lets you execute code regardless of the result. Beware though, the control flow statements of try and catch blocks will be suspended until the execution of the finally block finishes.



Got any JavaScript Question?