Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been reading back and forth between this post and the docs and I'm still not really getting it.

Is this just a way of registering a single callback to respond to error events that could be emitted by different operations? What are some examples when this would be better than handling error events individually?

Is it sort of like a try/catch for error events?



> Is it sort of like a try/catch for error events?

Yes, but it's also sort of like a try/catch for thrown errors.

    d = domain.create()
    d.on('error', function(e) {
      console.error('an error: ', e)
    });
    d.run(function() {
      throw new Error("whoops")
    })
would console.log, rather than crashing the program.

When an EventEmitter is bound to a domain, their error events and any errors thrown while emitting an event on them will be handled by the domain object that they're bound to.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: