Javascript: Which parameters are there for the onerror event with image objects? How to get additional details on an error related to an image?

HumanInDisguise picture HumanInDisguise · Feb 16, 2015 · Viewed 13.6k times · Source

I'm writing an application in JavaScript that should create a new image. Sometimes it fails. I was able to detect the times when it does by attaching an image.onerror event listener. Question is: How may I learn what error occured - what parameters does the error object for images bring? So far I only found out that

image.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
  console.log('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber
  + ' Column: ' + column + ' StackTrace: ' +  errorObj);
}

which I got from: javascript: how to display script errors in a popup alert?

returns Error: [object Event] Script: undefined Line: undefined Column: undefined StackTrace: undefined and in the error object I couldn't find anything related to message or error code.

Answer

Peti29 picture Peti29 · Feb 25, 2016

AFAIK the image.onerror handler will receive a single Event parameter that doesn't contain any info on the cause of the error.