Skip to content

Instantly share code, notes, and snippets.

@awerlang
Created November 16, 2016 15:25
Show Gist options
  • Save awerlang/a0abdbc102220e92f16a3479e1ce894e to your computer and use it in GitHub Desktop.
Save awerlang/a0abdbc102220e92f16a3479e1ce894e to your computer and use it in GitHub Desktop.
Sample implementation of a custom error
class CustomError extends Error {
get name(): string { return 'CustomError'; };
public stack: any;
constructor(public code: number, public message: string) {
super(message);
if (typeof (<any>Error).captureStackTrace === 'function') {
(<any>Error).captureStackTrace(this, this.constructor);
} else {
this.stack = (<any>(new Error())).stack;
}
}
toString() {
return this.name + '[' + this.code + ']: ' + this.message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment