aspx Tutorial

NET Articles,jQuery demo, with jQuery, online tutorial,Jquery, SilverLight, Javascript,,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here


Get our toolbar!


Posted by Aamir Hasan   on Thursday, October 18, 2012 Total Views:  


In this example, you will see how to handle runtime error on client side using java script. Why we need to add try catch in our java script function because to avoid syntax error, a logical error, a read/write error and client error.

<!DOCTYPE html>


<head runat="server">


    <script type="text/javascript">

        function calc() {

            try {

                var i = 1 / 0;

                document.getElementById('msg').innerHTML = i;

            } catch (e) {

                document.getElementById('msg').innerHTML = "Error" + e.message;






    <form id="form1" runat="server">

        <input type="button" value="Click" onclick="calc();"/>

        i/0 = <div id="msg"></div>




In above example, divided by zero will always give exception undefined. I have put the operation in try catch which will throw exception.



See live demo

Category: All | Javascript
Protected by Copyscape Online Plagiarism Tool

Comments (2) -

Jovita Rebman
Jovita Rebman United States
6/28/2015 6:37:26 AM #

I do not even know how I finished up right here, but I thought this post was good. I don't recognize who you might be but certainly you are going to a well-known blogger should you are not already. Cheers!|

Romeo Savage
Romeo Savage United States
7/13/2015 7:42:26 AM #

Thank you, I have just been searching for info approximately this subject for a while and yours is the greatest I've discovered till now. But, what concerning the bottom line? Are you certain about the supply?|

Add comment

  Country flag

  • Comment
  • Preview

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5