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:
- function errorHandle() {
- window.onerror = function(error, url, line, column, errorObj) {
- alert('Error: '+error+' Script: '+url+' Line: '+line+' Column: '+column+' StackTrace: '+errorObj);
- return true;
- };
- }
- // Then use a try/catch block to handle it
- try {
- errorHandle();
- } catch (e) {
- if (e != "") {
- alert('Errors: ' + e);
- var myerrors = e; //pseudo code
- // If e contains 'Script error.' then do something
- if (e.indexOf("Script error.") != -1) {
- alert('Script error was found');
- }
- }
- }
Thanks for the help.