Global error handling in browsers

suggest change

Syntax

Parameters

Parameter Details
eventOrMessage window.onerror is called as (message, url, lineNumber, colNumber, error). addEventListener("error", ...) receives one ErrorEvent instead. Very old browsers may omit the later arguments.
url When onerror is called with more than one argument, the second is the URL of the script that threw.
lineNumber If a handler is called with more than 1 argument, the third argument is a line number inside the JavaScript source file.
colNumber If a handler is called with more than 1 argument, the fourth argument is the column number inside the JavaScript source file.
error If a handler is called with more than 1 argument, the fifth argument is sometimes an Error object describing the problem.

Remarks

window.onerror was implemented differently across older browsers, so the later arguments are not reliable everywhere. A cross-origin script that lacks CORS reports "Script error." and does not expose the message, URL, or stack. Returning true from window.onerror suppresses the browser's default reporting in browsers that still honor that return value. window.onerror does not catch unhandled promise rejections; those go to unhandledrejection.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents