define-exceptions

1.0.17 • Public • Published

define-exceptions

Single exception

var de = require('define-exceptions');
var SuperException = de.Exception(Error, 'SuperException', 'Super new exception with %foo% and %bar%');

console.log(SuperException instanceof Error); // true

throw new SuperException({foo: 'test1', bar: 'test2'});
//SuperException: Super new exception with test1 and test2

Multiple exceptions

//exceptions.js
var de = require('define-exceptions');

var DiException = de.Exception(Error, 'DiException', 'Unknown MicroDi exception');

var Exceptions = de.Exceptions(DiException, {
    ProtoNotFound: 'Prototype not found in path %path%, params: %params%',
});

Exceptions.DiException = DiException;

module.exports = Exceptions;

Assertions

var Exceptions = require('./exceptions');



throw new Exceptions.ProtoNotFound({path: '/path/to', params: [1, 2, 3]});

Exceptions.ProtoNotFound.ok(false, {path: '/path/to', params: [1, 2, 3]});

Readme

Keywords

Package Sidebar

Install

npm i define-exceptions

Weekly Downloads

2

Version

1.0.17

License

MIT

Last publish

Collaborators

  • zerkalica