0

I would like to get the code to be printed of a function when there is an error. For example I have overwritten the window.onerror function and when there is an error I want to print the complete function. Of course I get the line number but that does not work for minified js. I could implement the use of source maps but isn't there a more easy way to get the complete function in which the error happened? For example:

function example(){
     //runs code which works but then an error happens
}

Now I want to print not only the one line where the error happened I want to print the whole function.

Sebastian Grebe
  • 657
  • 1
  • 8
  • 23
  • Chrome (and IE10) now give you the column number as the fourth argument in the window.onerror callback. So you can detect where is the error in your minfied js. – RPallas Jul 01 '15 at 15:14
  • That is right but this does only give me the line in which the error happened but I do not know where the function began since I want to get the whole function not just the line with the error. – Sebastian Grebe Jul 01 '15 at 15:16
  • Yes, but in modern browsers, you can know the line and the column, so you can know the function. https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror (column is the fourth arg) – RPallas Jul 01 '15 at 15:19
  • How can print the complete function when I know the row and the column that is a bit unclear to me at the moment. – Sebastian Grebe Jul 01 '15 at 15:41

0 Answers0