Skip to content

Instantly share code, notes, and snippets.

@Rantanen
Created April 11, 2012 01:34
Show Gist options
  • Save Rantanen/2356193 to your computer and use it in GitHub Desktop.
Save Rantanen/2356193 to your computer and use it in GitHub Desktop.
var CustomError = function (msg, code) {
Error.call(this, msg);
this.code = code;
}
CustomError.prototype = Object.create(Error.prototype);
function throwError() {
throw new CustomError("Throwing custom error", 123);
}
try {
throwError();
} catch (err) {
if (err instanceof CustomError) {
console.log("Custom error, code: " + err.code);
}
if (err instanceof Error) {
console.log("Custom error is still an error");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment