Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Error() constructor creates Error objects.
Note: Error() can be called with or without new. Both create a new Error instance.
A human-readable description of the error.
options OptionalAn object that has the following properties:
cause OptionalA value indicating the specific cause of the error, reflected in the cause property. When catching and re-throwing an error with a more-specific or useful error message, this property can be used to pass the original error.
fileName OptionalThe path to the file that raised this error, reflected in the fileName property. Defaults to the name of the file containing the code that called the Error() constructor.
lineNumber OptionalThe line number within the file on which the error was raised, reflected in the lineNumber property. Defaults to the line number containing the Error() constructor invocation.
When Error is used like a function, that is without new, it will return an Error object. Therefore, a mere call to Error will produce the same output that constructing an Error object via the new keyword would.
It is sometimes useful to catch an error and re-throw it with a new message. In this case you should pass the original error into the constructor for the new Error, as shown.
For a more detailed example see Error > Differentiate between similar errors.
JavaScript only tries to read options.cause if options is an object — this avoids ambiguity with the other non-standard Error(message, fileName, lineNumber) signature, which requires the second parameter to be a string. If you omit options, pass a primitive value as options, or pass an object without the cause property, then the created Error object will have no cause property.
| ECMAScript® 2027 Language Specification # sec-error-constructor |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.