Favorites

JavaScript Error Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Error
JavaScript Errors · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

Error objects represent problems that happen while code runs. They are thrown with throw, caught with try...catch, and carry a message, a name and usually a stack trace.

Description

An Error object describes a runtime error. When something goes wrong, JavaScript throws an instance of Error or one of its subtypes, such as TypeError or RangeError, and you can throw your own with the throw statement. Every error has a name and a message, and browsers add a non-standard stack property showing where it happened.

The optional cause option lets you wrap a lower-level error while keeping the original, which is useful when rethrowing. You can create your own error types by extending Error with a class; set this.name in the constructor so the type shows up in messages.

Built-in subclasses describe specific kinds of problem: TypeError, RangeError, SyntaxError, ReferenceError, URIError, EvalError and AggregateError. Use instanceof in a catch block to handle them differently. Anything can be thrown in JavaScript, including strings, but always throwing Error objects gives you a stack trace and a consistent shape for logging.

Creating

new Error(message)
new Error(message, { cause })

Instance properties

NameDescription
Error.prototype.causeThe cause property of an Error records the original error that led to it, so wrapped errors keep their underlying reason.
Error.prototype.messageThe message property of an Error holds the human-readable description of what went wrong.
Error.prototype.nameThe name property of an Error gives its type, such as Error, TypeError or a custom name.

Example

try {
  throw new Error('Something broke');
} catch (err) {
  console.log(err.name + ': ' + err.message);
}

class ValidationError extends Error {
  constructor(message) { super(message); this.name = 'ValidationError'; }
}
const e = new ValidationError('Email is required');
console.log(e instanceof Error, e.name);

const wrapped = new Error('Save failed', { cause: e });
console.log(wrapped.cause.message);

Browser Support

The following information will show you the current browser support for the Error object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee