Triggering window.onerror
Ajaxian covers a post on logging client-side errors on the server-side using AJAX. A commenter made mention of inconsistent behaviour when using the onerror
event as detailed on PPK.
In determining the issue, I noticed what appeared to be the issue and left the following comment on Ajaxian:
For example, trying to run
myfunction()
where myfunction doesn't exist will trigger onerror. But runningmyfunction(
where there's a missing bracket will not trigger it.
In actuality, upon further testing, this seems to be incorrect. PPK's test case definitely demonstrates something peculiar with the onerror
but in any of the test cases I created, I was able to trigger onerror
whether it was a syntax or runtime error. My suspicion at this point lies in the fact that PPK's test case expects the error handler to pass in the event object. It would appear that onerror
actually passes in the error message, file name and line number as parameters instead.
Conversation
That should rather read "as detailed on quirksmode.org by PPK" :-)
Your absolutely right. onerror doesn't pass the event object and instead passes the msg, url, and line number.
Also note for those using Prototype, Event.observe will not correctly observe onerror. When I was writing logger.js (http://encytemedia.com/treasure/file/javascript/logger/logger.js) I had to use window.onerror instead.