JavaScript throw Statement

You are Here:

JavaScript throw Statement

The throw statement can be used within a try block of code to create your own run-time errors.

When an exception occurs in the try block, JavaScript will normally stop, and control will be passed to the catch block with user-defined exception (message).

Note: If no catch block exists among caller functions, the program will terminate.


HTML Online Editor
<!DOCTYPE html> <html> <body> <p id="point"></p> <script> var x = document.getElementById("point"); var num = 50; try{ if(num < 100) throw "Number is less than 100"; else x.innerHTML = num; } catch(e){ x.innerHTML = "Error : "+ e; } </script> </body> </html>


throw "custom error text"


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author