JavaScript Exception Handling Example

Nov 24, 2021 . Admin



Hello Friends,

Now let's see example of how to use exception handling example. We will check how to use exception handling. This is a short guide on use exception handling in javascript. Here you will learn how to use javascript exception handling. Let's get started with how to use exception handling in javascript.

Here i will give you many example how to use exception handling using javascript.

Example : 1
<html>
    <head>
        <title>JavaScript Exception Handling Example - MyWebtuts.com</title>
    </head>
    <body>
        <h3>JavaScript Exception Handling Example - MyWebtuts.com</h3>
        <script>
            try{
                var a1 = ["96","82","64","20","15","70","30"];
                document.write(a1);
                document.write(temp);
            }catch(e){
                alert("There is error which shows "+e.message);
            }
        </script>
    </body>
</html>  
Output :
There is error which shows temp is not defined(Alert Message)
96,82,64,20,15,70,30
Example : 2
<html>
    <head>
        <title>JavaScript Exception Handling Example - MyWebtuts.com</title>
    </head>
    <body>
        <h3>JavaScript Exception Handling Example - MyWebtuts.com</h3>
        <script>
            try{
                var a1=2;
                if(a1==2)
                document.write("ok <br>");
            }
            catch(Error){
                document.write("Error found"+e.message);
            }
            finally{
                document.write("Value of a1 is 50 ");
            }
        </script>
    </body>
</html>  
Output :
ok
Value of a1 is 50

It will help you...

#Javascript