Skip to content

Instantly share code, notes, and snippets.

@rdarder
Created December 29, 2015 20:31
Show Gist options
  • Save rdarder/cc532cd97b69a5f97030 to your computer and use it in GitHub Desktop.
Save rdarder/cc532cd97b69a5f97030 to your computer and use it in GitHub Desktop.
preconditions
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