RDUK - errors
Installation
npm install rduk-errors --save --save-exact
Usage
var errors = ;
You can instantiate a new error from the available errors. see the list
var myarg = 1; try var err = 'myarg' myarg; throw err; catcherr console; // will output true console; // will output true
or throw it directly
try errors; catcherr console; /** * will output: * { [ArgumentError: Invalid argument "myarg" (value: "1").] * name: 'ArgumentError', * message: 'Invalid argument "myarg" (value: "1").' } */
You can also add your own custom error
/* FakeError.js */ { 'use strict'; module { FakeErrorsuper_; }; } module; /* main.js */var errors = ;errors; try errors; catch err console; // will output true
By default, your custom error inherits BaseError
. The BaseError
class is in charge
to initialize all error specific properties.
/* BaseError.js */ { 'use strict'; module { Error; thisname = thisconstructorname; thismessage = message; }; ; } require module;
But you can, if needed, inherit from your own custom error
var errors = ; errors; try errors; catch err /* ... */
Available errors
errors.ArgumentNullError
(propertyName
);errors.ArgumentError
(propertyName
,propertyValue
);errors.ArgumentOutOfRangeError
(propertyName
);errors.ConfigurationError
(message
);errors.NotImplementedError
(methodName
);errors.NotSupportedError
(methodName
);