[Webkit-unassigned] [Bug 8519] WebCore doesn't fire window.onerror event.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Nov 18 17:19:26 PST 2006


http://bugs.webkit.org/show_bug.cgi?id=8519


jcostell at tibco.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jcostell at tibco.com




------- Comment #2 from jcostell at tibco.com  2006-11-18 17:19 PDT -------
If someone takes the effort to implement onerror, it would be great if it
improves upon the usefulness of the current implementations in Internet
Explorer and Firefox. In my opinion, the true value of window.onerror is to
approximate this common Java idiom that provides invaluable error diagnostics
to programmers:

public static void main(String[] args) {
  try {
    ...
  } catch (Throwable t) {
    t.printStackTrace();
    System.exit(1);
  }
}

Because JavaScript in a browser is so event-driven, it is tedious to impossible
to wrap every entry point in a JavaScript try/catch block. It would be nice if
window.onerror could act as the catch block in the main method in the Java code
sample above. For this to be the case, the call stack of the thrown exception
must be available in the onerror method. Ideally, the actual thrown exception
object should also be available. 

Internet Explorer currently provides the call stack of the line where the
exception was raised by introspecting arguments/caller/callee. The exception
object not available. (The standard arguments to onerror are message, file, and
line number). Unfortunately, if an object is explicitly thrown with the "throw"
statement, the message argument to onerror is always "Exception thrown and not
caught". And of course, the file argument is always the HTML page hosting the
JavaScript, not the actually JavaScript file. 

Firefox has its own weaknesses. The three arguments to onerror are typically
useful. The message is relevant even if the error was thrown with the throw
statement. The line number and file URL even pinpoint the JavaScript line that
threw the exception even if that line is in an external JavaScript function.
Unfortunately, the uncaught exception object is not available in the onerror
function. Worse, there is no way to get the call stack of the exception, even
through arguments/caller/callee. Since Firefox already supports the Error.stack
property, it would make more sense for them to just expose the uncaught
exception object.

My suggestion for Safari (and Firefox) is to either add a 4th argument to the
onerror function that is the uncaught exception object, or to set a property of
the window object to the last uncaught exception. 

See also: https://bugzilla.mozilla.org/show_bug.cgi?id=355430


-- 
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list