Error cause
The cause property of errors records the specific original cause of the error, particularly for errors that have been re-thrown.
Overview
The cause property of errors records the specific original cause of the error, particularly for errors that have been re-thrown.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 93 | 93 | 91 | 15 | 93 | 15 | |
| Built-in object | ||||||
Error.Error.options cause parameter `options.cause` parameter | 93 | 93 | 91 | 15 | 93 | 15 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
- Before version 125, default console logging for `Error` objects does not print the cause.
Notes 1 item(s)
Implementation note
- Before version 125, default console logging for `Error` objects does not print the cause.
Notes 1 item(s)
Implementation note
- Default console logging for `Error` objects does not print the cause.
Notes 1 item(s)
Implementation note
- Before version 125, default console logging for `Error` objects does not print the cause.
Notes 1 item(s)
Implementation note
- Default console logging for `Error` objects does not print the cause.
Syntax
JAVASCRIPT
try {
const data = JSON.parse(invalidJson);
} catch (err) {
throw new Error('Failed to load data', { cause: err });
}
// Access the original error via err.cause Live demo
Use cases
Using Error cause
The cause property of errors records the specific original cause of the error, particularly for errors that have been re-thrown.
Cautions
- No specific concerns. Stable across all major browsers.
Accessibility
- When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.
Related links
Powered by web-features