Created
July 28, 2015 09:29
-
-
Save edwardbeckett/f652b94030168e7c7e95 to your computer and use it in GitHub Desktop.
Argument 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
<script> | |
function InvalidArgumentException( message){ | |
this.message = message; | |
if("captureStackTrace" in Error) { | |
Error.captureStackTrace( this, InvalidArgumentException ); | |
} else { | |
this.stack = (new Error()).stack; | |
} | |
} | |
InvalidArgumentException.prototype = Object.create( Error.prototype ); | |
InvalidArgumentException.prototype.name = "InvalidArgumentException"; | |
InvalidArgumentException.prototype.constructor = InvalidArgumentException; | |
function parseVal(val) { | |
if( typeof(val) !== "string"){ | |
throw new InvalidArgumentException( "Error : Argument of type [string] required, [" + typeof(val) + "] given."); | |
} | |
console.group( "Type of argument = [" + typeof(val) + "]" + " is valid... "); | |
return val; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment