JavaScript Error Handling Part – 2
Free Web development courses with real-time projects Start Now!!
Program 1
<html> <head> <script> try { // hello() let a=100,b=0 if(b==0) throw new Error("Division Error") c=a/b console.log(c) } catch(e) { // console.log("Unable to devide by zero") // console.log(e.name) console.log(e.message) // console.log(e.stack) } </script> </head> <body> <center> <h1>Check error in code</h1> </center> </body> </html>
Program 2
<html> <head> <script> try { hello() } catch(e) { console.log(e.message) } try { let a=10,b=0 if(b==0) throw new Error("division error") } catch(e) { console.log(e.message) //console.log("Value is: "+a) } // try // { // let i=-3 // let str="Java script code" // let n=str.length // if(i>=0 && i<n) // console.log(str.charAt(i)) // else // throw new Error("Index out of bound") // } // catch(e) // { // console.log(e.message) // } // finally // { // console.log("This is finally block code") // } </script> </head> <body> <center> <h1>Check error in code</h1> </center> </body> </html>
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google