Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out this Fiddle:</p> <p><a href="http://jsfiddle.net/xYsRA/1/">http://jsfiddle.net/xYsRA/1/</a></p> <pre><code>window.onerror = function (msg, url, line) { console.log("Caught[via window.onerror]: '" + msg + "' from " + url + ":" + line); return true; // same as preventDefault }; window.addEventListener('error', function (evt) { console.log("Caught[via 'error' event]: '" + evt.message + "' from " + evt.filename + ":" + evt.lineno); console.log(evt); // has srcElement / target / etc evt.preventDefault(); }); throw new Error("Hewwo world. I crash you!!!"); throw new Error("Hewwo world. I can only crash you once... :("); </code></pre> <p>Which prints:</p> <pre>Caught[via window.onerror]: 'Uncaught Error: Hewwo world. I crash you!!!' from http://fiddle.jshell.net/xYsRA/1/show/:32 fiddle.jshell.net:21 Caught[via 'error' event]: 'Uncaught Error: Hewwo world. I crash you!!!' from http://fiddle.jshell.net/xYsRA/1/show/:32 fiddle.jshell.net:26 ErrorEvent {lineno: 32, filename: "http://fiddle.jshell.net/xYsRA/1/show/", message: "Uncaught Error: Hewwo world. I crash you!!!", clipboardData: undefined, cancelBubble: false…} fiddle.jshell.net:27\ </pre> <p>Notes:</p> <ul> <li><p>If you remove the "return true" / "evt.preventDefault()" lines, then after the error is logged, it will print on the JS console in the normal way.</p></li> <li><p>Contrary to statements made above, window.onerror worked in all the browsers I tested. However, the addEventListener method is probably better anyways and provides richer semantics.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload