error-x

3.1.2 • Public • Published

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

error-x

Create custom Javascript Error objects.

module.exports

Want to create your own Error objects, this module will allow you to do just that. It ships with all the standard ErrorConstructor objects already created for you. Why? Well, these offer some improvements over the native versions.

  • They have a toJSON method and so they can be serialised.
  • They have a standardised stack property, using error-stack-parser messages and stacks are parsed and then re-formatted.
  • They have a frames property which is an array of the parsed stack message, so you have easy access to the information.

Kind: Exported member

module.exports.AssertionErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new AssertionErrorConstructor_new([message])

Error constructor for test and validation frameworks that implement the standardized AssertionError specification.

Param Type Description
[message] Object Need to document the properties.

module.exports.ErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new ErrorConstructor([message])

The Error constructor creates an error object.

Param Type Description
[message] string Human-readable description of the error.

module.exports.EvalErrorConstructor ⇐ EvalError

Kind: static class of module.exports
Extends: EvalError

new EvalErrorConstructor_new([message])

Creates an instance representing an error that occurs regarding the global function eval().

Param Type Description
[message] string Human-readable description of the error.

module.exports.InternalErrorConstructor ⇐ Error

Kind: static class of module.exports
Extends: Error

new InternalErrorConstructor_new([message])

The InternalError object indicates an error that occurred internally in the JavaScript engine. For example: "InternalErrorConstructor: too much recursion".

Param Type Description
[message] string Human-readable description of the error.

module.exports.RangeErrorConstructor ⇐ RangeError

Kind: static class of module.exports
Extends: RangeError

new RangeErrorConstructor_new()

Creates an instance representing an error that occurs when a numeric variable or parameter is outside of its valid range.

Type Description
string [message] Human-readable description of the error.

module.exports.ReferenceErrorConstructor ⇐ ReferenceError

Kind: static class of module.exports
Extends: ReferenceError

new ReferenceErrorConstructor_new([message])

Creates an instance representing an error that occurs when de-referencing an invalid reference

Param Type Description
[message] string Human-readable description of the error.

module.exports.SyntaxErrorConstructor ⇐ SyntaError

Kind: static class of module.exports
Extends: SyntaError

new SyntaxErrorConstructor([message])

Creates an instance representing a syntax error that occurs while parsing code in eval().

Param Type Description
[message] string Human-readable description of the error.

module.exports.TypeErrorConstructor ⇐ TypeError

Kind: static class of module.exports
Extends: TypeError

new TypeErrorConstructor([message])

Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.

Param Type Description
[message] string Human-readable description of the error.

module.exports.URIErrorConstructor ⇐ URIError

Kind: static class of module.exports
Extends: URIError

new URIErrorConstructor([message])

Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.

Param Type Description
[message] string Human-readable description of the error.

module.exports.supportsAllConstructors : boolean

Indicates if the Javascript engine supports subclassing of all Error types. If true then all are supported, if false (only very old browsers IE6) then only Error is supported.

Kind: static property of module.exports

module.exports.create([name], [ECTR])function

Creates a custom Error constructor. Will use ErrorConstructor if argument is not a valid constructor.

Kind: static method of module.exports
Returns: function - The custom Error constructor.

Param Type Default Description
[name] string "'Error'" The name for the custom Error.
[ECTR] function Error Error constructor to be used.

Example

import * as errorX from 'error-x';
 
const MyError = errorX.create('MyError'); // Uses `Error` as no constructor
// specified.
const err = new MyError('somethingHappened');
 
JSON.stringify(err); // => see below.
// A serialised error, showing the custom error object's structure and
// format
// {
//   "name": "MyError",
//   "message": "somethingHappened",
//   "frames": [
//     {
//       "functionName": "Y.x",
//       "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
//       "lineNumber": 65,
//       "columnNumber": 13,
//       "source": "Y.x (http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13)"
//     },
//     {
//       "functionName": "window.onload",
//       "fileName": "http://fiddle.jshell.net/2k5x5dj8/183/show/",
//       "lineNumber": 73,
//       "columnNumber": 3,
//       "source": "window.onload (http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3)"
//     }
//   ],
//   "stack": "MyError\n    Y.x()@http://fiddle.jshell.net/2k5x5dj8/183/show/:65:13\n    window.onload()@http://fiddle.jshell.net/2k5x5dj8/183/show/:73:3"
// }

module.exports.isErrorConstructor(value)boolean

Determine whether or not a given value is an Error type.

Kind: static method of module.exports
Returns: boolean - Returns true if value is an Error type, else false.

Param Type Description
value * The object to be tested.

Package Sidebar

Install

npm i error-x

Weekly Downloads

2

Version

3.1.2

License

MIT

Unpacked Size

1.81 MB

Total Files

11

Last publish

Collaborators

  • xotic750