title: catching error event message from firefox
body: <p>I can't find a way to catch the error message under firefox:</p>
  
  <pre><code>window.addEventListener("error", handleException, false);
  
  ...
  
  function handleException(e) {   
      alert(e);
      return false;
  }
  
  ...
  
  &lt;script&gt;
  throw new Error('sdasd');
  &lt;/script&gt;
  </code></pre>
  
  <p>This enters very well the <code>handleException</code> method however the <code>e</code> parameter is an <code>error event</code> under firefox <strong>and I don't know how to get the associated message</strong>.
  In chrome for instance, I get either the message through <code>e.message</code> because after the error bubbles up to not being caught, there's an automatic error fired at window level (See <a href="http://jsfiddle.net/fz9y8/" rel="nofollow">this fiddle</a>: the final error is "Uncaught") that contains the original error that I raised manually.</p>
  
  <p>So to have the same behaviour under firefox (if you run the fiddle under firefox you'll see that the message is "undefined") I found a workaround consisting in encapsulating an error raising function to setup a manual "last error" architecture:</p>
  
  <pre><code>function err(I_sText) { 
      g_lastManualError = new Error(I_sText);
      throw g_lastManualError; //this variable is global so I can get the message from anywhere
  }
  </code></pre>
  
  <p>So instead of doing <code>throw new Error(..)</code> I only call <code>err(..)</code>. That works, at least for user defined exceptions, which are my biggest concern. In my handler <code>handleException</code> I'm consulting the global variable.</p>
  
  <p>Do you know how I could do otherwise? I'm not happy with this solution.</p>
  
  <p>Thank you,
  S.</p>