Categories
JavaScript Answers

How to print JavaScript exception stack trace?

Spread the love

Sometimes, we want to print JavaScript exception stack trace.

In this article, we’ll look at how to print JavaScript exception stack trace.

How to print JavaScript exception stack trace?

To print JavaScript exception stack trace, we can use the stack property of an Error instance.

For instance, we write

console.log(new Error().stack);

to create a new Error instance and then get the stack trace from the stack property.

Then we use console.log to log the stack trace.

We put this in the line where we want to print the stack trace to the console.

Conclusion

To print JavaScript exception stack trace, we can use the stack property of an Error instance.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.