JavaScript Global error handling in browsers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • window.onerror = function (eventOrMessage, url, lineNumber, colNumber, error) { ... }

Parameters

ParameterDetails
eventOrMessageSome browsers will call the event handler with just one argument, an Event object. However, other browsers, especially the older ones and older mobile ones will supply a String message as a first argument.
urlIf a handler is called with more than 1 argument, the second argument usually is an URL of a JavaScript file that is the source of the problem.
lineNumberIf a handler is called with more than 1 argument, the third argument is a line number inside the JavaScript source file.
colNumberIf a handler is called with more than 1 argument, the fourth argument is the column number inside the JavaScript source file.
errorIf a handler is called with more than 1 argument, the fifth argument is sometimes an Error object describing the problem.

Remarks

Unfortunately, window.onerror has historically been implemented differently by each vendor. The information provided in the Parameters section is an approximation of what to expect across different browsers and their versions.



Got any JavaScript Question?