Catching errors inside window.onerror?
<p>I've setup a <code>window.onerror</code> handler to catch errors. Its purpose? To concat a string for each time an error occurs, then another handler <code>window.onunload</code> sends it off to the Server. (Presumably with all the errors).</p>

<p>Problem is, it's only able to send the first error over, because after the <code>onerror</code> handler event fires for the first time, the error isn't caught and thus the script terminates...</p>

<p>Is there a way around this?</p>

<pre><code>ErrorManager: (function () {
        function Init(message) {
            InitErrorHandler();
            InitAjaxHandler();
            setTimeout("Interface.ErrorManager.SendErrorsToAjax()", 8000);
        }
        function InitErrorHandler() {
            Data.ErrorHandlerText = "";
            Data.ErrorHandlerCount = 0;
            window.onerror = function(errorMessage, url, line) {
                if(IsInIgnoreList(errorMessage)) { return; }
                Data.ErrorHandlerText += ("Error: "+(Data.ErrorHandlerCount+1)+" &lt;br /&gt;&lt;br /&gt;");
                //Get error specific info
                Data.ErrorHandlerText += escape(errorMessage) + "&lt;br /&gt;";
                Data.ErrorHandlerText +=  escape(url) + "&lt;br /&gt;";
                Data.ErrorHandlerText +=  escape(line) + "&lt;br /&gt;";
                Data.ErrorHandlerCount++;
                console.log("BOOM"+errorMessage);
            }
        }

        function InitAjaxHandler() {
            window.onbeforeunload = function() { //when browser closed
                Data.ErrorHandlerCount &gt; 0 &amp;&amp; SendErrorsToAjax();
            }
        }
        function SendErrorsToAjax() {
            PrepareErrorsForAjax();
            $.getJSON(Interface.Utility.PrefixURL('/ajax/sendfeedback/handlejserrors/'+Data.ErrorHandlerText));
        }
        function IsInIgnoreList(str) {
            return str.indexOf('nsIDOMSVGLocatable') != -1 ? true : false;
        }

        function PrepareErrorsForAjax() {
            var preText = "&lt;br /&gt;&lt;br /&gt;A user has encountered a few errors: &lt;br /&gt;&lt;br /&gt;";
            //Get session info
            var userAgent, activePageID, accountNO, consumerNO;
            userAgent = escape(navigator.userAgent);
            preText += "User agent: "+userAgent+" &lt;br /&gt;";

            if($.mobile.activePage) {
                activePageID = $.mobile.activePage.attr('id');
                preText += "Page ID: "+activePageID+" &lt;br /&gt;";
            }
            //Get info that may or may not be set
            console.log("AUTH JSON "+Data.authJSON);
            console.log("CONSUMER JSON "+Data.authJSON.consumers);
            if(Data.authJSON &amp;&amp; localStorage.lastConsumerNo) {
                preText += "Account Number: " +Data.authJSON.accountId+" &lt;br /&gt;";
                preText += "Consumer Number: "+ localStorage.lastConsumerNo+" &lt;br /&gt;";
            }
            preText += "&lt;br /&gt; The following errors were encountered:&lt;br /&gt;&lt;br /&gt;";
            Data.ErrorHandlerText = preText + Data.ErrorHandlerText;
        }
        return {
            Init: Init,
            SendErrorsToAjax: SendErrorsToAjax
        }
    })(),
</code></pre>
