JavaScript Error Methods

About This Index
This page is the JavaScript Error Methods index. The Error object has three methods. Each row below links to a full guide with syntax, examples you can run, and FAQs.
Learn what an Error is on /js/error. Use this page when you need a specific method such as toString().
Error.captureStackTrace() and Error.isError() are called on the Error constructor itself. toString() is called on an error object, for example err.toString().
How to Call an Error Method
Call the static methods on Error and the instance method on an error object:
const err = new Error("Disk full");
// instance method: call it on an error object
err.toString(); // "Error: Disk full"
// static methods: call them on Error itself
Error.isError(err); // true
Error.isError("Disk full"); // false
const report = { name: "ReportError", message: "Report failed" };
Error.captureStackTrace(report); // report.stack is now a string JavaScript Error Methods Table
All method guides in this JavaScript tutorial series (3 tutorials), grouped by what they do.
Static methods (call on Error)
2 methodsHelpers you call on the Error constructor itself, not on an error object.
| Method | Description | Tutorial |
|---|---|---|
Error.captureStackTrace() | Add a stack property to any object, and hide a helper function from it with the second argument. | Open |
Error.isError() | Return true when a value is a real Error object; more reliable than instanceof Error. | Open |
Instance method (call on an error object)
1 methodAvailable on every error you create or catch.
| Method | Description | Tutorial |
|---|---|---|
toString() | Return one line of text, name: message. JavaScript calls it for you in String(err) and in "text" + err. | Open |
Frequently Asked Questions
Start with toString()
Open the guide for turning an error into readable text: syntax, examples, and FAQs.
10 people found this page helpful
