Sophon Aniketos
Sophon Aniketos

Reputation: 737

How to print the cause for a thrown Error in Chrome console?

Since July 2021 they have added a new error cause property in Javascript, so we are able to do:

throw new Error('New error message', { cause: err });

In Firefox this err object is shown after the original error. On Chrome only the original error is shown, and I can't store the thrown error into variable to inspect it. How do I see the error cause then? (Without modifying the source code / get into the debugger)

Upvotes: 7

Views: 1306

Answers (1)

fregante
fregante

Reputation: 31858

Starting in Chrome 125, the developer tools will now automatically display the cause chain: https://developer.chrome.com/blog/new-in-devtools-125#error-cause

Screenshot of a dev tools console containing a "Caused by" chain

Upvotes: 10

Related Questions