This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
domain.on('error') should suppress other uncaughtException handlers #4375
Labels
Comments
After |
Yes, we should move the default error handling function to a separate function that checks for a current domain, and emits error on it, or emits 'uncaughtException' on the process object. |
isaacs
added a commit
to isaacs/node-v0.x-archive
that referenced
this issue
Dec 27, 2012
This adds a process._fatalException method which is called into from C++ in order to either emit the 'uncaughtException' method, or emit 'error' on the active domain. The 'uncaughtException' event is an implementation detail that it would be nice to deprecate one day, so exposing it as part of the domain machinery is not ideal. Fix nodejs#4375
Guys, it seems a bit off topic, but what techniqie would you recommend to re-throw errors from nested domains' error handlers to their parents' error handlers? |
@AlexeyKupershtokh You could do something like this: var domain = require('domain');
var parentDomain = domain.create();
parentDomain.on('error', function(er) {
console.error('parent got it:', er.message);
});
var myDomain = domain.create();
myDomain.on('error', function(er) {
if (!myDomainShouldHandleThisError(er))
parentDomain.emit('error', er);
});
myDomain.run(function() {
setTimeout(function() {
undefined_reference;
});
});
function myDomainShouldHandleThisError(er) {
// lazy kid...
return false;
} Output:
|
This was referenced Feb 2, 2013
isaacs
added a commit
to isaacs/node-v0.x-archive
that referenced
this issue
Apr 2, 2013
This adds a process._fatalException method which is called into from C++ in order to either emit the 'uncaughtException' method, or emit 'error' on the active domain. The 'uncaughtException' event is an implementation detail that it would be nice to deprecate one day, so exposing it as part of the domain machinery is not ideal. Fix nodejs#4375
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Coming from a mocha issue, I realized the following:
Example:
A possible workaround would be to wrap your
uncaughtException
handler in aprocess.nextTick
and then check forerr.domain
, but that means domains are backwards incompatible with existinguncaughtException
handlers for example in 3rd party modules like mocha.The text was updated successfully, but these errors were encountered: