JavaScript – Advanced Learning

JavaScript – Advanced Learning

Error Handling in JavaScript

web designing institutes, web development institutes in gurgoan, web designing courses, web development courses, top web designing institutes in gurgaon,

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>

javascript tutorial, Basic Javasript, Javascript course, javascript

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>

Comments are closed.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2017/11/14/javascript-2
YouTube61
YouTube