Skip to content

zerkalica/define-exceptions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]});

About

Exceptions define library

Resources

License

Stars

Watchers

Forks

Packages

No packages published