- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to catch all JavaScript unhandled exceptions?
To catch all JavaScript unhandled exceptions, use window.error. The onerror event handler provides three pieces of information to identify the exact nature of the error −
- Error message − The same message that the browser would display for the given error
- URL − The file in which the error occurred
- Line number− The line number in the given URL that caused the error
Example
You can try to run the following code to catch unhandled exceptions −
<html> <head> <script> <!-- window.onerror = function (msg, url, line) { alert("Message : " + msg ); alert("url : " + url ); alert("Line number : " + line ); } //--> </script> </head> <body> <p>Click the following to see the result:</p> <form> <input type = "button" value = "Click Me" onclick = "myFunc();" /> </form> </body> </html>
- Related Articles
- How to catch exceptions in JavaScript?
- How to catch all the exceptions in C++?
- How to catch all JavaScript errors?
- How can we create an exception filter to handle unhandled exceptions in C# ASP.NET WebAPI?
- Is it possible to catch multiple Java exceptions in single catch block?
- How to catch many exceptions at the same time in Kotlin?
- How to catch multiple exceptions in one line (except block) in Python?
- How to define custom JavaScript exceptions?
- How to use Custom Exceptions in JavaScript?
- How to catch syntax errors in JavaScript?
- How to catch any JavaScript exception in Clojurescript?
- How does Exceptions Handling work in JavaScript?
- How to Handle Exceptions in Ruby
- How can I write a try/except block that catches all Python exceptions?
- Explain Optional Catch Binding in JavaScript.

Advertisements