Although we have seen the Exceptions provided by JavaScript. But sometimes, we need to create our own Exception.
And luckily, JavaScript provides an throw statement, that can help you define your own exception.
<html> <body> <script> var number = 23 try { if (number < 50) { throw "Number cannot be less than 50" } } catch(err) { document.write("There is an error :: "+err) } </script> </body> </html>
So, if you see the above output. We have raised the same exception, without defining a class.
All we have done is used the throw statement, passing the message, Number cannot be less than 50.
throw "Number cannot be less than 50"
And we were able to raise our custom exception.