Well exception doesn't always mean error.
When programming by exception you may very well use an exception as a
"current action" stopper, no matter how deep in said action (understand call
depth) the code throwing it is (exception zealots don't really like it when
you blatlantly say it but it's basically an über break/return/goto, you name
it).
I think that's the issue Dan is talking about: throwing an exception in one
callback shouldn't stop the whole callback loop. Indeed, if you think about
it, callbacks generally come from separate entities/plugins and should be
sandboxed. IIRC, in jQuery, you can return false to prevent further
callbacks to be executed and this probably should be the only instance when
it happens.
Apparentely, on top of that, Dan wanna know what went wrong. Not sure I
follow him on that, I'd be perfectely happy with the try/catch solution for
each callback.
The main issue I have with Dan approach is that he makes the assumption it
is the responsibility of the callback dispatcher to ignore/report the
exception. I knida disagree with that. The dispatcher has no way of
differenciating between semantic/applicative exceptions and runtime
exceptions. Only the creator of the callback can. Thus the callback should
be of that form:
function() {
try {
// code
}
catch (exception) {
// If exception is semantic, report to owner and ignore
// else throw it again
}
}
Now, the real design decision becomes: in case of a runtime error in one
callback should the others be penalized and not executed. And, said like
that, yes it becomes a bit ridiculous because these kind of exceptions
should never be raised in the first place unless there is a programatic
error (probably not properly controlled inputs in a deployment environment).
Jeez, I didn't mean to make a wall of text... I don't even know if I make
any sense.
Anyway, I disagree with you John in that exception=error and I disagree with
Dean is that it is the responsibility of the dispatcher to deal with
exceptions.
I'm not gonna make a lot of friends ;)
Regards to both of you and thanks for all the work you do. I don't say much
most of the time but you make my life easier on a daily basis.
-- Julian
2009/3/24 John Resig <[email protected]>
>
> I don't understand the point of it - so you have code that throws an
> exception (obviously indicating that something is broken) and you
> expect it to do what... still try to run? Exceptions are the universal
> indicator that something is broken and not working. I understand his
> implementation but he doesn't answer the question: Why would you want
> this?
>
> --John
>
>
>
> On Tue, Mar 24, 2009 at 3:49 PM, Cloudream <[email protected]> wrote:
> > http://deanedwards.me.uk/weblog/2009/03/callbacks-vs-events/
> > Maybe good feature to add in 1.4?
> >
> > Best regards,
> > Chi Cheng
> > --
> > jQuery UI
> > http://jqueryui.com/
> >
> > >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---