reportError(throwable)
Parameters
Return value
None (undefined
).
Exceptions
TypeError
-
The method is called without an error argument.
Examples
Feature test for the method using:
if (typeof window.reportError === "function") {
/ function is defined
}
The following code shows how you might create and report an error, and how it may be caught using either the onerror
event handler property or by adding a listener for the error
event.
Note that the handler assigned to onerror
must return true
to stop the event propagating further.
const newError = new Error("Some error message", "someFile.js", 11);
window.reportError(newError);
window.onerror = (message, source, lineno, colno, error) => {
console.error(`message: ${error.message}, lineno: ${lineno}`);
return true;
};
window.addEventListener("error", (error) => {
console.error(error.filename);
});
/ Output
/ > "message:Some error message, lineno: 11"
/ > "someFile.js"
Specifications
Specification |
---|
HTML # runtime-script-errors |
Browser compatibility
BCD tables only load in the browser
See also
Window
WorkerGlobalScope.reportError()
error
eventerror
eventerror
event