31

In node.js if you catch uncaughtExceptions, like so:

process.on('uncaughtException', function (error) {
  console.log(error);
});

The error message displayed doesn't contain all the information that you receive if you don't catch the error and just let the process crash. When you let the process crash it includes what line caused the error. Is there any way to get the full error message including the line that caused the error so we can log this data using uncaughtException.

1
  • 3
    This question itself has solved my problem :) Thanks a lot :) Commented Jan 2, 2014 at 7:16

2 Answers 2

66

Try error.stack

process.on('uncaughtException', function (error) {
   console.log(error.stack);
});
Sign up to request clarification or add additional context in comments.

2 Comments

How to show more, because in my case, error.stack just show 3 row, I can not trace the root of issue raising the error
upvoted! isnt error.stack a nonstandard extension developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… or does node have it everywhere
7

Try:

process.on('uncaughtException', function (error) {
   console.dir(error);
});

2 Comments

Sir, Any difference between the question and the answer?
@Jayram Yes. The question used console.log(error) and I suggestion using console.dir(error). Different functions on the console object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.