Skip to content

Instantly share code, notes, and snippets.

@ralphtheninja
Created December 11, 2017 12:52
Show Gist options
  • Save ralphtheninja/a62c0bcee51fef0bccf1a3eb3c0c703d to your computer and use it in GitHub Desktop.
Save ralphtheninja/a62c0bcee51fef0bccf1a3eb3c0c703d to your computer and use it in GitHub Desktop.
node-errno
const create = require('.').create
const CustomError = require('.').custom.CustomError
const inherits = require('inherits')
// inherits from CustomError (which inherits from Error)
const MyError = create('MyError')
const MyError3 = create('MyError3', MyError)
// same but using traditional inheritance
function MyError2 (message, cause) {
CustomError.call(this, message, cause)
}
inherits(MyError2, CustomError)
function bar () {
console.log(new MyError().stack)
console.log(new MyError2('MyError2', 'woot').stack)
console.log(new MyError3('MyError3', 'woot').stack)
}
function foo () {
bar()
}
foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment