Languages
[Edit]
EN

JavaScript - get error line number, column number, message, stack, type, etc.

10 points
Created by:
christa
600

In this short article, we would like to show how to get error line number, column number, message, stack, type, etc. using JavaScript.

Quick solution:

Handle window.onerror event at the source code beginning.

 

Practical example

Edit

Web browser JavaScript provides prcised details about occurred error location only when window.onerror event is used. In the below examples you can find 2 cases: unhandled exception, and syntax error.

Warning: the solution may be not working when files are run from file system, so it can be good to use some server to test examples locally.

Unhandled exception

Edit

Syntax error

Edit

 

Internet Explorer

Edit

In this section, you can find legacy version that works also under Microsoft Internet Explorer.

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join