JavaScript reportError()
Anonymous contributor
Published Mar 7, 2025
Contribute to Docs
reportError() is a function of the window interface that is used to report errors to the console or global event listeners, such as browser’s error handler. It ensures that the errors are properly reported and improves debugging and monitoring.
Syntax
The reportError() function takes in an instance of the Error object as a single parameter:
window.reportError(error);
Example 1
The following example uses reportError() to log an error object:
const myError = new Error('Error Message 1', 'File.js', 7);window.reportError(myError);
Example 2
The reportError() function can also be used with the try..catch block to report caught errors:
try {throw new Error('Wrong execution!');} catch (error) {window.reportError(error);}
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours