Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett
Created July 28, 2015 09:29
Show Gist options
  • Save edwardbeckett/f652b94030168e7c7e95 to your computer and use it in GitHub Desktop.
Save edwardbeckett/f652b94030168e7c7e95 to your computer and use it in GitHub Desktop.
Argument Exception Handler
<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