Reputation: 61382
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?
Upvotes: 7
Views: 170
Reputation: 79830
I think window.onerror handler will provide you such a functionality where you can alert the erorr, url and the line number,
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>
Upvotes: 2