Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js - better error handling than process.on('uncaughtException', fn)?

Node.js - better error handling than process.on('uncaughtException', fn)?

Problem

At the top of my app, I have this code:

process.on('uncaughtException', function(err) {
  console.log("We found an uncaught exception.");
  console.log(err);
});

And if I search my logs for grep -i -A10 -B3 'uncaught exception' logfile, I can get some decent info. But I have no idea what execution context the exception got thrown in, what the error was, and so forth.

What pattern should I use instead?

Problem courtesy of: Zachary Burt

Solution

The "err" argument of uncaughtException is an object and you can request some of its properties to get more information for that error. As an example you can use its "stack" property to have a better understanding about where the error is coming from:

console.log(err.stack);

See: http://docs.nodejitsu.com/articles/errors/what-is-the-error-object

Solution courtesy of: jonjbar

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js - better error handling than process.on('uncaughtException', fn)?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×