ApplicationException class

Defines a base class to defive various application exceptions.

Most languages have own definition of base exception (error) types. However, this class is implemented symmetrically in all languages supported by PipServices toolkit. It allows to create portable implementations and support proper error propagation in microservices calls.

Error propagation means that when microservice implemented in one language calls microservice(s) implemented in a different language(s), errors are returned throught the entire call chain and restored in their original (or close) type.

Since number of potential exception types is endless, PipServices toolkit supports only 12 standard categories of exceptions defined in ErrorCategory. This ApplicationException class acts as a basis for all other 12 standard exception types.

Most exceptions have just free-form message that describes occured error. That may not be sufficient to create meaninful error descriptions. The ApplicationException class proposes an extended error definition that has more standard fields:

  • message: is a human-readable error description
  • category: one of 12 standard error categories of errors
  • status: numeric HTTP status code for REST invocations
  • code: a unique error code, usually defined as 'MY_ERROR_CODE'
  • correlation_id: a unique transaction id to trace execution through a call chain
  • details: map with error parameters that can help to recreate meaningful error description in other languages
  • stack_trace: a stack trace
  • cause: original error that is wrapped by this exception

ApplicationException class is not serializable. To pass errors through the wire it is converted into ErrorDescription object and restored on receiving end into identical exception type.

See ErrorCategory See ErrorDescription

Implemented types
  • Exception
Implementers

Constructors

ApplicationException([String category String correlation_id String code String message ])
Creates a new instance of application exception and assigns its values. [...]

Properties

category ↔ String
Standard error category
read / write
cause ↔ String
read / write
code ↔ String
A unique error code
read / write
correlation_id ↔ String
A unique transaction id to trace execution throug call chain
read / write
details StringValueMap
A map with additional details that can be used to restore error description in other languages
read / write
message ↔ String
A human-readable error description (usually written in English)
read / write
stack_trace ↔ String
Stack trace of the exception
read / write
status ↔ int
HTTP status code associated with this error type
read / write
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

getCauseString() → String
Gets original error wrapped by this exception as a string message. [...]
getStackTraceString() → String
Gets a stack trace where this exception occured. [...]
setCauseString(String value) → void
Sets original error wrapped by this exception as a string message. [...]
setStackTraceString(String value) → void
Sets a stack trace where this exception occured. [...]
toString() → String
Returns a string representation of this object.
override
withCause(dynamic cause) ApplicationException
Sets a original error wrapped by this exception [...]
withCode(String code) ApplicationException
Sets a unique error code. [...]
withCorrelationId(String correlationId) ApplicationException
Sets a correlation id which can be used to trace this error through a call chain. [...]
withDetails(String key, dynamic value) ApplicationException
Sets a parameter for additional error details. This details can be used to restore error description in other languages. [...]
withStackTrace(String stackTrace) ApplicationException
Sets a stack trace for this error. [...]
withStatus(int status) ApplicationException
Sets a HTTP status code which shall be returned by REST calls. [...]
wrap(dynamic cause) ApplicationException
Wraps another exception into an application exception object. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited

Static Methods

unwrapError(dynamic error) → dynamic
Unwraps original exception through wrapped exception objects. [...]
wrapError(ApplicationException error, dynamic cause) ApplicationException
Wraps another exception into specified application exception object. [...]