Prototype callback functions swallow exceptions

Using the prototype version 1.6.0.2.

I have a common problem when exceptions are swallowed, when they are thrown into the callback function, usually when I try to process the response to the call Ajax.Request. Here is a simple example:

HTML markup:

<input type="button" id="myButton" value="Press Me" />

JavaScript:

MYSITE = {};

document.observe("dom:loaded", function () {

    // Set up our helper object
    MYSITE.pageHelper = new MYSITE.PageHelper();

});


MYSITE.PageHelper = function() {

    console.log("PageHelper called.");

    $("myButton").observe("click", this.makeCall.bindAsEventListener(this));

};

MYSITE.PageHelper.prototype.makeCall = function() {

    console.log("Make call.");

    new Ajax.Request(
            "remoteCall.cfm", 
            {
                method: 'get', 
                parameters: "", 
                onComplete: this.handleCallback.bindAsEventListener(this)

            });


};

MYSITE.PageHelper.prototype.handleCallback = function(resp) {

    console.log("Start callback processing...");

    var x = missingVar + "text"; // This line generates an exception...

    console.log("Finished callback processing.");
};

OK, so the problem is that if you run this code in Firefox using Firebug, an exception will be thrown for the violation string - it is swallowed. Gulp. The only way to recognize them (say if I'm debugging) is to wrap the contents of the callback function in try / catch. For instance:

MYSITE.PageHelper.prototype.handleCallback = function(resp) {

    try {

        console.log("Start callback processing...");

        var x = missingVar + "text"; // This line generates an exception...

        console.log("Finished callback processing.");

    } catch (e) {
        console.log(e);
    }
};

Has anyone else encountered this problem? Any workarounds out there?

Thanks in advance!

+5

All Articles