Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

make-error

Package Overview
Dependencies
0
Maintainers
3
Versions
22
Issues
File Explorer

Advanced tools

make-error

Make your own error types!

    1.3.6latest

Version published
Maintainers
3
Weekly downloads
18,440,262
increased by6.46%

Weekly downloads

Readme

Source

make-error

Package Version Build Status PackagePhobia Latest Commit

Make your own error types!

Features

  • Compatible Node & browsers
  • instanceof support
  • error.name & error.stack support
  • compatible with CSP (i.e. no eval())

Installation

Node & Browserify/Webpack

Installation of the npm package:

> npm install --save make-error

Then require the package:

var makeError = require("make-error");

Browser

You can directly use the build provided at unpkg.com:

<script src="https://unpkg.com/[email protected]/dist/make-error.js"></script>

Usage

Basic named error

var CustomError = makeError("CustomError"); // Parameters are forwarded to the super class (here Error). throw new CustomError("a message");

Advanced error class

function CustomError(customValue) { CustomError.super.call(this, "custom error message"); this.customValue = customValue; } makeError(CustomError); // Feel free to extend the prototype. CustomError.prototype.myMethod = function CustomError$myMethod() { console.log("CustomError.myMethod (%s, %s)", this.code, this.message); }; //----- try { throw new CustomError(42); } catch (error) { error.myMethod(); }

Specialized error

var SpecializedError = makeError("SpecializedError", CustomError); throw new SpecializedError(42);

Inheritance

Best for ES2015+.

import { BaseError } from "make-error"; class CustomError extends BaseError { constructor() { super("custom error message"); } }

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Julien Fontanet

Keywords

FAQs

What is make-error?

Make your own error types!

Is make-error popular?

The npm package make-error receives a total of 15,530,067 weekly downloads. As such, make-error popularity was classified as popular.

Is make-error well maintained?

We found that make-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 3 open source maintainers collaborating on the project.

Last updated on 19 Feb 2020

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc