1.0.2 • Published 4 years ago

@enterprize/exceptions v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Enterprize Exceptions (etz-exceptions)

Tired of using the plain Error class? Want some common Exceptions out of the box? Want to add details in an elegant and typed way? Start using Enterprize Exceptions!

npm version

Features

Jokes aside :grin:, the following exceptions are implemented out of the box:

  • Exception
  • IllegalArgumentException
  • IllegalStateException
  • NotImplementedYetException
  • UnsupportedOperationException

Extend any of the above to create your custom exception.

Public API

Exception<D = void> extends Error

Base class of all exceptions. This class and its subclasses are exceptions that are not considered critical (i.e. they are not catastrophic errors), and the application can be safely recovered if the exception is treated by a try-catch block.

Generic types:

  • D: (optional) The type of the details argument. Default: void

Inherits: Error

Constructors

  • constructor()
  • constructor(message: string)
  • constructor(message: string, details: D)
ArgumentsTypeDescription
messagestringSimple text message. Same parameter as in Error. Default: "Exception"
detailsDSome data that represents details of the exception. Can be anything.

Attributes

AttributeTypeDescription
namestringName of the error. Default: The class name (or its subclass)
messagestringError message. Default: "Exception"
stackstringError stack caputured.

IllegalArgumentException<D = void> extends Exception<D>

Indicates that a method or constructor received an illegal or inappropriate parameter/argument.

Generic types:

  • D: (optional) The type of the details argument. Default: void

Inherits: Exception

Constructors:

  • constructor()
  • constructor(message: string)
  • constructor(message: string, argumentName: string)
  • constructor(message: string, argumentName: string, details: D)
ArgumentsTypeDescription
messagestringSimple text message. Same parameter as in Error. Default: "Exception"
argumentNamestringName of the argument or parameter that caused the exception.
detailsDSome data that represents details of the exception. Can be anything.

Attributes

See Inherits for the inherited attributes.

AttributeTypeDescription
argumentNamestringName of the argument that caused the exception.

IllegalStateException<D = void> extends Exception<D>

Signals that a method has been invoked at an illegal or inappropriate time. In other words, the NodeJS environment, NodeJS application or the resource is not in an appropriate state for the requested operation.

Generic types:

  • D: (optional) The type of the details argument. Default: void

Inherits: Exception

Constructors:

  • constructor(message: string)
  • constructor(message: string, details: D)
ArgumentsTypeDescription
messagestringSimple text message. Same parameter as in Error. Default: "Exception"
detailsDSome data that represents details of the exception. Can be anything.

Attributes

See Inherits for the inherited attributes.

NotImplementedYetException<D = void> extends Exception<D>

Indicates that an method/function/constructor is not yet implemented but will be available in the future.

Generic types:

  • D: (optional) The type of the details argument. Default: void

Inherits: Exception

Constructors

  • constructor(message: string)
  • constructor(message: string, details: D)
ArgumentsTypeDescription
messagestringSimple text message. Same parameter as in Error. Default: "Exception"
detailsDSome data that represents details of the exception. Can be anything.

Attributes

See Inherits for the inherited attributes.

UnsupportedOperationException<D = void> extends Exception<D>

Indicates that a given operation is not supported and never will be.

Generic types:

  • D: (optional) The type of the details argument. Default: void

Inherits: Exception

Constructors:

  • constructor(message: string)
  • constructor(message: string, reason: string)
  • constructor(message: string, reason: string, details: D)
ArgumentsTypeDescription
messagestringSimple text message. Same parameter as in Error. Default: "Exception"
reasonstringThe reason for the operation not being supported.
detailsDSome data that represents details of the exception. Can be anything.

Attributes

See Inherits for the inherited attributes.

AttributeTypeDescription
reasonstringThe reason for the operation not being supported..

Sponsor

Use my packages in your projects? You think they are awesome? So, help me give more time to develop them by becoming a sponsor. :wink: