It's nice to be able to distinguish error types by classes. But it's a bit tricky to correctly create a custom error class in Node.js, so here is an example. The example also shows how to add an extra parameter called `extra` that will be stored as a property on the error. ### Usage ``` js var CustomError = require('./errors/custom-error'); function doSomethingBad() { throw new CustomError('It went bad!', 42); } ``` ### Features * **Name appears once** - less editing if you have to create lots of custom error classes * **Easy to subclass** - just change the last line to inherit from another custom error class you created * **Correct stack trace** - no extra stack frames, no double capturing of the stack trace ### Anti-patterns These are some things that I've seen in other proposed solutions that you should avoid. * `Error.call(this)` - creates another error object (wasting a bunch of time) and doesn't touch `this` at all * `Error.captureStackTrace(this, arguments.callee);` - works, but `arguments.callee` is deprecated, so don't use it * `this.stack = (new Error).stack` - this... I don't even...