0

There must be a way to prevent crashes in every mistake. I'm using this:

try
{
    // blabla
    throw "Error";
}
catch(err)
{
    self.Error(err);
}

but I can not be continuously capturing them

user1629569
  • 661
  • 1
  • 4
  • 17
  • 4
    For synchronous operations, `try..catch` should work fine. But, since most Node APIs are asynchronous, they won't complete within the same call stack as `try..catch`. These will usually offer an `'error'` event [you can add a listener to](http://nodejs.org/api/events.html#events_emitter_on_event_listener). But, it depends on the API. See "[Node.js Best Practice Exception Handling](http://stackoverflow.com/questions/7310521/node-js-best-practice-exception-handling)" for more. – Jonathan Lonowski Feb 26 '14 at 20:22
  • Or, the `Error` will just be passed as an argument to a callback (`function (err, arg0)`). `throw` statements aren't actually all that common with Node.js due to the asynchronous focus. – Jonathan Lonowski Feb 26 '14 at 20:33
  • Nodejs crashes? Or you mean, how can I ignore errors/exceptions in my code? In your example, it looks like you are in control of throwing the exception and handling it. It is not clear to me what you are trying to achieve. – Xotic750 Feb 26 '14 at 20:39

0 Answers0