Created
April 11, 2012 01:34
-
-
Save Rantanen/2356193 to your computer and use it in GitHub Desktop.
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
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