reportError()

Anonymous contributor's avatar
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

Contribute to Docs

Learn JavaScript on Codecademy