In this JavaScript tutorial, we will use onerror event of window object and provide a handler function which tells which line of JavaScript coding is throwing the Error. This video also explains parameters received by the onerror event handler function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<!DOCTYPE html> <head> <Title> Java Script Windows </Title> </head> <body> <Script type="text/javascript"> function FaultyOne() { //Sample 01: Without Exception Handler var theNumber = document.getElementById("ANumber").value; theNumber = TheNumber + 1; document.getElementById("SayThanks").innerHTML += "1. Thank You <br>"; } //Sample 02: Error Handler window.onerror = function(message, source, LineNo, ColNo ) { document.write("Error Message:- <br>"); document.write(message + "<br>"); document.write("Source Location:- <br>"); document.write(source + "<br>"); document.write("Line No | Col No:- <br>"); document.write(LineNo + " | " + ColNo + "<br>"); } </Script> <input type="text" id="ANumber" value="650" /> <input type="button" value="No Exception" onclick="FaultyOne()"/> <h3 id="SayThanks"></h3> <h3 id="ReportError"></h3> </body> </html> |
Categories: JavaScript-Tube