4

If an unhandled exception occur in javascript code all browsers create beauty message in its log including exception type, message and stack trace and/or useful link to the source line. Now I want to catch an exception, put the same log as unhandled exception, and continue execution. I tried to write something like

try {
...
} catch (e) {
console.log(e);
}

but all I got in Chrome is the exception type name in the log without any description and stack or source line link. How to create beautiful exception log message same as unhadled exception but for caught exception and continue execution?

1

1 Answer 1

4

You can use the stack property of the Error object to get a stack trace.

If you're not throwing the exception yourself, you could wrap it in an error obect to provide a trace to the catch block at least.

try{
  throw new Error("Test");

}
catch(e){
  console.log(e.stack);
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.