# custom-error

> Create custom errors that inherit Error

Latest version **0.2.1** (published 2014-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install custom-error
pnpm add custom-error
yarn add custom-error
bun add custom-error
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2014-12-29 |
| First published | 2014-06-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andre Z. Sanchez |
| Maintainers | andrezsanchez |
| Keywords | error, inherit, prototype |

## Links

- npm: https://www.npmjs.com/package/custom-error
- Repository: https://github.com/andrezsanchez/custom-error
- Issues: https://github.com/andrezsanchez/custom-error/issues
- npm.io page: https://npm.io/package/custom-error

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2014-12-29
- 0.2.0 — 2014-11-18
- 0.1.1 — 2014-06-14
- 0.1.0 — 2014-06-14

## README

# custom-error

Create custom errors that inherit Error.

[![build status](https://secure.travis-ci.org/andrezsanchez/custom-error.png)](http://travis-ci.org/andrezsanchez/custom-error)

# why

Extending Error is a real [pain](http://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript), so this library deals with the quirks, providing a clean API to extend Error that works across JS environments, including Node and browsers.

# usage

Calling `customError(errorTitle[, ParentError])` creates a new error class that can be called the
same way that `Error` is called. The new error constructor will inherit from `Error`, or from
`ParentError` if you provide it.

# examples

``` js
var customError = require('custom-error');

var ApocalypseError = customError('ApocalypseError');

ApocalypseError() instanceof Error           // true
ApocalypseError() instanceof ApocalypseError // true

var UnixApocalypseError = customError('UnixApocalypseError', ApocalypseError)

UnixApocalypseError() instanceof Error                 // true
UnixApocalypseError() instanceof ApocalypseError       // true
UnixApocalypseError() instanceof UnixApocalypseError   // true

if (new Date().getFullYear() === 2038) {
  throw UnixApocalypseError('OH NOES')
}
```

## Using prototype

``` js
UnixApocalypseError.prototype.year = 2038

try {
  throw UnixApocalypseError()
}
catch (err) {
  console.log(err.year) // 2038
}
```


# installation

``` bash
npm install custom-error
```

# license

MIT

---
_Source: https://npm.io/package/custom-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
