Created
November 16, 2015 02:33
-
-
Save Teino1978-Corp/41471e3a6485a8e883e4 to your computer and use it in GitHub Desktop.
Javascript: Lean Exception handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* lsauer, 2013 | |
* Lean handler for exception reporting; stdout is set by default to console.log | |
* @param {exc} exc an Exception instance of Error, containing a message and stack property | |
* @param {exc} stdOut A variadic function for error reporting. By default: console.log | |
* @return undefined | |
*/ | |
var exceptionHandler = function(exc, stdOut){ | |
var stdOut = stdOut || function() { console.log.apply(console, arguments) }; | |
if(stdOut instanceof Function){ | |
if(exc instanceof Error){ | |
stdOut('Exception:', exc.message, '; Stack:', exc.stack, '; Scope:', this.toString()); | |
}else{ | |
stdOut('Exception missing. Argument:', exc); | |
} | |
}else{ | |
if(exc instanceof Error){ | |
exceptionHandler._log.push('Exception:' + exc.message +';' + exc.stack + '; Argument: '+ stdOut.toString()); | |
}else{ | |
exceptionHandler._log.push('Exception missing.; Argument(s): '+ exc.toString() + ', ' + stdOut.toString()); | |
} | |
} | |
}; | |
/** @var {array} _log internal log history for custom functionality */ | |
exceptionHandler._log = []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment