Created
December 29, 2015 20:31
-
-
Save rdarder/cc532cd97b69a5f97030 to your computer and use it in GitHub Desktop.
preconditions
This file contains 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
module Preconditions { | |
class UnexpectedNullException extends Error { | |
} | |
export function checkNotNull<T>(reference:T):T { | |
if (reference === null || reference === undefined) { | |
throw new UnexpectedNullException(); | |
} | |
return reference; | |
} | |
class IllegalArgumentException extends Error { | |
} | |
export function checkArgument(expression:boolean):void { | |
checkNotNull(expression); | |
if (!expression) { | |
throw new IllegalArgumentException() | |
} | |
} | |
class IllegalStateException extends Error { | |
} | |
export function checkState(expression:boolean):void { | |
checkNotNull(expression); | |
if (!expression) { | |
throw new IllegalStateException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment