Note that there are some explanatory texts on larger screens.

plurals
  1. POlog errors with stack trace in javascript
    text
    copied!<p>I'm trying to log javascript errors on a productive site. So far it worked quite well with the following code included in the site:</p> <pre><code>function catcherr(errorMessage, url, line) { var parameters = "msg=" + escape(errorMessage) + "&amp;url=" + escape(url) + "&amp;line=" + escape(line); new Image().src = "/error.gif?" + parameters; return false; }; window.onerror = catcherr; </code></pre> <p>I'm trying to add a stack trace to the errors to get more information. This basically works with the following idea including into the function above:</p> <pre><code> try { i.dont.exist += 0; } // does not exist - that's the point catch (e) { if (e.stack) // Firefox { // do some stuff </code></pre> <p>I use jquery, a simple example:</p> <pre><code>&lt;script type="text/javascript"&gt; jQuery(document).ready(function() { p.foo += 1; // this should throw an error // do stuff }); &lt;/script&gt; </code></pre> <p>The funny part is, that when I have an error inside the "ready" function of jquery, the part "try { i.dont.exist += 0; }" does not throw any exception anymore and the engine stops without any error. With the example above, and catcherr extended as follows, only "1" gets alerted:</p> <pre><code>function catcherr(errorMessage, url, line) { try { alert(1); i.dont.exist += 0; alert(4);} catch(e) { alert(5);} alert(2); var parameters = "msg=" + escape(errorMessage) // ... } </code></pre> <p>Anyone having an idea why this breaks, when an error occurs inside the "ready" function of jquery?</p>
 

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