Hello, I've recently started using prototype 1.5 or a large project. It's been a great experience so far.
As I've been developing, I noticed that many times exceptions raised by errors in my code (such as, say, trying to use some property of a null object, etc.) would not show up in my javascript console (I am using Firebug). More troubling were exceptions that the code explicitly threw that also mysteriously vanished. I just worked around this for a while by interspersing console.log statements at key places in the code I was working on, but I eventually became curious about why errors would sometimes appear and other times not. I looked more closely at prototype.js and found 3 empty catch blocks (Try.these, Ajax.Responders.dispatch, Event.stopObserving). The one that was affecting me was in dispatch(). I found that Ajax.Request.dispatchException() invokes Responders.dispatch for onException callbacks, so I added Ajax.Responders.register({ onException: function(req, e) { throw e; } }); to my code, but the empty catch block in Ajax.Responders.dispatch() catches all exceptions raised by responders and discards them. I tried editing dispatch() to always throw errors that it catches; afterwards exceptions successfully appear in my console. I'm using this workaround now: Ajax.Responders.register({ onException: function(req, e) { console.log(e); } }); and it works well for me. I wanted to relate this experience to you because I feel that the empty catch block in dispatch() (I can't comment on the others), violates the "principle of least surprise". I expected (and perhaps I shouldn't have?) uncaught exceptions to show up in my console and stop execution since this is the default behavior. Perhaps there are strong reasons for choosing to use an empty catch block in dispatch(), but if there are not I would suggest allowing exceptions raised by responders to be thrown, or at least to do something like this (admittedly ugly) compromise: dispatch: function(callback, request, transport, json) { var dispatched = false, exception = null; this.each(function(responder) { if (typeof responder[callback] == 'function') { try { responder[callback].apply(responder, [request, transport, json]); dispatched = true; } catch (e) { exception = e; } } }); if (!dispatched && exception && (callback == 'onException')) { throw exception; } } Thanks for developing such a useful library. Best wishes, -Ben --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---