7

Whenever my JavaScript dies while logging an error message to the Console, I’d like to be told about this immediately. The console is too invisible and often hidden or obscured by other windows.

Can I have something as prominent as a .NET exception dialog? To me these JavaScript errors are completely fatal; they aren’t something that can be ignored, and I’d like to know about them before I spend a while wondering why something doesn’t happen.

Are there addons that do this for Firefox or Chrome?

2
  • 2
    Fantastic question. Somehow I always just accepted that the JS console is “enough”, but now you got me thinking — why aren’t they more splat-in-your-face so that you notice them? Are implementors of JS interpreters afraid of hurting the JS developer’s ego? Commented Mar 6, 2012 at 15:14
  • Some thing like window.onerror = function(e) {alert(e)} ? Commented Mar 6, 2012 at 15:24

1 Answer 1

2

I think window.onerror handler will provide you such a functionality where you can alert the erorr, url and the line number,

DEMO

Note: Make sure window.onerror function is inside a separate script tag like below. Any error logged in error console will be alerted.

<script> window.onerror = function(msg, url, lineNo) { alert(msg + '\n' + url + '\n Line No: ' + lineNo); } </script> <script> document.getElementById('test').asd = 123; //will throw an error </script> <script> var s = [{]}; </script> <script> throw "Custom Error"; </script> 
Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly. Why didn’t anyone tell me about this before? :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.