JavaScript – Advanced Learning

JavaScript – Advanced Learning

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>

 

Errors- Additional Details

<script type=”text/javascript”>

<!– three  variables msg, url and line here   –>

window.onerror = function (msg, url, line)

{

alert(msg);

alert(“Dcoument Name: ” + url + “At Line Number ” + line );

}

 

</script>

</head>

<body>

<input type=”button” value=”Test Error” onclick=”test()” />

</body>

</html>

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/09/29/javascript-advanced-learning-2
YouTube41
YouTube