window.onerror - Read console log & handle specific error

window.onerror - Read console log & handle specific error

Hi Guys,

I'm trying to read the errors in the console log & then do something if a particular error is thrown that says 'Script error.'
The following is some code I've pulled together and some commented pseudo code:

  1. function errorHandle() {
  2.     window.onerror = function(error, url, line, column, errorObj) {
  3.       alert('Error: '+error+' Script: '+url+' Line: '+line+' Column: '+column+' StackTrace: '+errorObj);
  4.       return true;
  5.     };
  6.   }
  7.   // Then use a try/catch block to handle it
  8.   try {
  9.     errorHandle();
  10.   } catch (e) {
  11.       if (e != "") {
  12.         alert('Errors: ' + e);
  13.         var myerrors = e; //pseudo code
  14.         // If e contains 'Script error.' then do something
  15.         if (e.indexOf("Script error.") != -1) {
  16.           alert('Script error was found');
  17.         }
  18.       }
  19.   }

Thanks for the help.