|
216 | 216 | };
|
217 | 217 |
|
218 | 218 | startup.processFatal = function() {
|
219 |
| - // call into the active domain, or emit uncaughtException, |
220 |
| - // and exit if there are no listeners. |
221 | 219 | process._fatalException = function(er) {
|
222 | 220 | var caught = false;
|
223 |
| - if (process.domain) { |
224 |
| - var domain = process.domain; |
225 |
| - var domainModule = NativeModule.require('domain'); |
226 |
| - var domainStack = domainModule._stack; |
227 | 221 |
|
228 |
| - // ignore errors on disposed domains. |
229 |
| - // |
230 |
| - // XXX This is a bit stupid. We should probably get rid of |
231 |
| - // domain.dispose() altogether. It's almost always a terrible |
232 |
| - // idea. --isaacs |
233 |
| - if (domain._disposed) |
234 |
| - return true; |
235 |
| - |
236 |
| - er.domain = domain; |
237 |
| - er.domainThrown = true; |
238 |
| - // wrap this in a try/catch so we don't get infinite throwing |
239 |
| - try { |
240 |
| - // One of three things will happen here. |
241 |
| - // |
242 |
| - // 1. There is a handler, caught = true |
243 |
| - // 2. There is no handler, caught = false |
244 |
| - // 3. It throws, caught = false |
245 |
| - // |
246 |
| - // If caught is false after this, then there's no need to exit() |
247 |
| - // the domain, because we're going to crash the process anyway. |
248 |
| - caught = domain.emit('error', er); |
249 |
| - |
250 |
| - // Exit all domains on the stack. Uncaught exceptions end the |
251 |
| - // current tick and no domains should be left on the stack |
252 |
| - // between ticks. |
253 |
| - var domainModule = NativeModule.require('domain'); |
254 |
| - domainStack.length = 0; |
255 |
| - domainModule.active = process.domain = null; |
256 |
| - } catch (er2) { |
257 |
| - // The domain error handler threw! oh no! |
258 |
| - // See if another domain can catch THIS error, |
259 |
| - // or else crash on the original one. |
260 |
| - // If the user already exited it, then don't double-exit. |
261 |
| - if (domain === domainModule.active) |
262 |
| - domainStack.pop(); |
263 |
| - if (domainStack.length) { |
264 |
| - var parentDomain = domainStack[domainStack.length - 1]; |
265 |
| - process.domain = domainModule.active = parentDomain; |
266 |
| - caught = process._fatalException(er2); |
267 |
| - } else |
268 |
| - caught = false; |
269 |
| - } |
| 222 | + if (process.domain && process.domain._errorHandler) { |
| 223 | + caught = process.domain._errorHandler(er); |
270 | 224 | } else {
|
271 | 225 | caught = process.emit('uncaughtException', er);
|
272 | 226 | }
|
| 227 | + |
273 | 228 | // if someone handled it, then great. otherwise, die in C++ land
|
274 | 229 | // since that means that we'll exit the process, emit the 'exit' event
|
275 | 230 | if (!caught) {
|
|
281 | 236 | } catch (er) {
|
282 | 237 | // nothing to be done about it at this point.
|
283 | 238 | }
|
284 |
| - } |
| 239 | + |
285 | 240 | // if we handled an error, then make sure any ticks get processed
|
286 |
| - if (caught) |
| 241 | + } else { |
287 | 242 | setImmediate(process._tickCallback);
|
| 243 | + } |
| 244 | + |
288 | 245 | return caught;
|
289 | 246 | };
|
290 | 247 | };
|
|
0 commit comments