Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.onerror in Safari ( Javascript )

I create an error message its working with IE and Mozila. Not woking with Safari, Chrome and Opera.

But I need to use it. Please give me right way for doing it.

<script language="javascript" type="text/javascript">
window.onerror = function(msg, url, line)
{
    document.write("Message\t = "+msg + "<br/>Location\t = " + url + "<br/>Line No.\t = " + line + "<br/>Error No.\t = " + this.err.number);
}
this.err = Error(12,"My Own Error");
throw this.err;
</script>

==========================================
Internet Explorer:

My Error
Message = My Own Error
Location = http://localhost/practice/JavaScript/window.errors.php
Line No. = 8
Error No. = 12 
================================================
Mozilla FireFox:

My Error
Message = Script error.
Location = My Own Error
Line No. = 0
Error No. = undefined 
=====================================================
Safari, Chrome, Opera:

My Error

look the code Mozilla give wrong information. what I do?

like image 354
Karandeep Singh Avatar asked Jun 22 '10 11:06

Karandeep Singh


1 Answers

Opera doesn't support window.onerror at all. Chrome supports it, but not on errors that you throw yourself. This is also true of Internet Explorer when using Error objects other than Error(), e.g. TypeError(). Chrome also doesn't provide the line and file arguments.

You should correctly catch any exceptions you're going to throw with a try...catch statement, instead of relying on window.onerror.

like image 126
Andy E Avatar answered Sep 20 '22 05:09

Andy E