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
Implementers

Constructors

ApplicationException([String? category, String? correlation_id, String? code, String? message])
Creates a new instance of application exception and assigns its values.
ApplicationException.fromJson(Map<String, dynamic> json)
factory

Properties

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

Methods

fromJson(Map<String, dynamic> json) → void
getCauseString() String?
Gets original error wrapped by this exception as a string message.
getStackTraceString() String?
Gets a stack trace where this exception occured.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
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.
toJson() Map<String, dynamic>
toString() String
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.

Operators

operator ==(Object 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.