Categories
JavaScript Answers

How to rethrow an exception in JavaScript, but preserve the stack?

Spread the love

Sometimes, we want to rethrow an exception in JavaScript, but preserve the stack.

In this article, we’ll look at how to rethrow an exception in JavaScript, but preserve the stack.

How to rethrow an exception in JavaScript, but preserve the stack?

To rethrow an exception in JavaScript, but preserve the stack, we just throw the exception.

For instance, we write

throw err;

to throw the err Error instance with throw.

Conclusion

To rethrow an exception in JavaScript, but preserve the stack, we just throw the exception.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.