edwardbeckett
7/28/2015 - 9:29 AM

Argument Exception Handler

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>