Skip to content

Instantly share code, notes, and snippets.

@watson
Created September 24, 2016 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watson/b46945a11c089fe74afa1e80739be4ac to your computer and use it in GitHub Desktop.
Save watson/b46945a11c089fe74afa1e80739be4ac to your computer and use it in GitHub Desktop.
Creating custom error types in Node.js
var util = require('util')
util.inherits(NotFoundError, Error)
throw new NotFoundError('foo')
function NotFoundError (message) {
Error.captureStackTrace(this, this.constructor)
this.name = this.constructor.name
this.message = message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment