The task is to have the process object emit an "uncaughtException"
event when an exception makes its way all the way down to the event
loop.
This task is of medium difficulty, it will be mostly or all in C++.
Probably FatalException() in node.cc is the right place to hook in. It
might also be that ReallyEmit() in node_events.cc is better. I'm not
sure, you'll have to play around with it and make some tests.
Maybe, once this is implemented a second commit can reimplement
ReportException() from node.cc in javascript (in src/node.js).
Generally this is a good idea, except that we have lots of event
handlers where we don't want to have to return true or false - e.g.
the "connection" event from tcp.Server. The default (returning
undefined) should mean that all event listeners are run. It might be
nice to have some sort of way of canceling the rest of the listeners
(returning true? calling EventEmitter.cancelListeners()? What does the
DOM do?). But for this case I have a different suggestion: How about
"throw e" to have a hard crash?
> returning true in any handler will stop the chain. If non returns true,
> you got an unhandled exception. Given this approach, it would be nice to
> have one special handler, that is always called last. that way, you can
> design focused handlers, that look for something specific and return
> false, if they don't find themself suitable. The generic one (the last
> hope or the clean up handler) will not have the comfort of ignoring
> exceptions.
Hm. Why true? I would have expected false. That's how it works in the
DOM doesn't it? At least for preventing the default action of an event.
And how about having two different event listeners? One for the "normal"
exceptions and one for all. This way you don't have to make the decision
based on the exception type in every handler (which seems like a design
flaw to me). I get the idea from the Ruby world. By default you only
catch exceptions that are subclass of RuntimeError (I think). You
explicitly have to catch all exceptions.
Urban
I think that for now, the unhandledException event should live along
side the normal unhandledException handler in C++ (which is, to print
a stack trace and exit). If someone registers an unhandledException
listener, then the default action is not taken. Let's think about
interrupting chains of listeners later...
Completed by Felix in 2b252ac.