JavaScript

JavaScript

JavaScript, initially called LiveScript is a robust client-side scripting language, used mainly for make your webpage more interactive. This also helps in communicate data between the server and the browser.

JavaScript is also used in game development and mobile application development. It Also help in reduce the traffic of server side.

JavaScript was developed by Brendan Eich in 1995, which appeared in Netscape, a popular browser of that time.

Please note that JavaScript and Java are very much unrelated. Java is a very complex programming language whereas JavaScript is only a scripting language.

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/08/12/640/
YouTube38
YouTube