Prev Demo
JavaScript
>
How To Handle Error In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Error Handling in JavaScript</h1> <script> function TestFunction() { try { CallAFunctionThatIsNotDefined(); } catch (e) { alert("Oops, an error occurred, sorry! Please try again later." + e); } } </script> <input type="button" id="btnTest" onclick="TestFunction()" value="Click me" /> <p><strong>Note:</strong> Click the button to fire the error occurred alert</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output