Error Handling in JavaScript

Exception is the major part of object-oriented programming as well as in JavaScript in details.

The try statement lets you test a block of code for errors. you may put those statements where exceptions or errors may occured.

The catch statement lets you handle the error.

The throw statement used to raise your own exception or custom errors.

The finally statement will execute whether an exception or error raise or not.

Example:

<html>

<head>

<script>

function test()

{

try

{

alerta(“Test”);

}

catch(err)

{

alert(“invalid keyword ” +err);

}

}

</script>

</head>

<body>

<input type=”button” value=”Run” onclick=”test()”>

</body>

</html>

author image

About admin

You Might Also Like...

Things to learn – Web Designing
Excel Right Left and Mid Functions

1 Comment

  1. nice read….

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/04/21/javascript-advanced-learning
YouTube75
YouTube