forked from nodejs/node-v0.x-archive
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New process.exceptionCatcher is inherited by callbacks.
This allows a web framework to catch at the top level exceptions thrown by page dispatch code, and to return a 500 Internal Server Error for that request without disturbing other requests. This works even if the page dispatch code is async. FatalException tries process.exceptionCatcher first before falling back to emitting an "uncaughtException" event. Whenever a callback is registered, EventEmitter.addListener() sets callback._exceptionCatcher to the current value of process.exceptionCatcher. When the callback is dispatched, EventEmitter.emit() sets process.exceptionCatcher to the callback's ._exceptionCatcher. In this way callbacks registered by callbacks also inherit the exceptionHandler. It is also possible to chain exceptionHandlers.
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78b69e7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saving the exception catcher on the callback is problematic and leads trivially to confusing cases. Observe: http://gist.github.com/283562
The way to avoid this situation might be to trap the current exceptionCatcher in a closure around the callback. Ie, something like:
callback = (function (ec, fn) { return function () { try { fn() } catch (ex) { ec(ex) } } })(process.exceptionCatcher, callback);
However, I'd be wary of that adding the extra scope closure around every callback.
I can't really comment on your C++, I'm sure it's lovely. That's how I'd avoid the problem in JavaScript, though.
I dig the rethrow default handler to support catch-and-release chaining.