Pip-Services-Commons-Dotnet
|
Defines a base class to defive various application exceptions. More...
Public Member Functions | |
ApplicationException () | |
Creates a new instance of application exception. More... | |
ApplicationException (string category=null, string correlationId=null, string code=null, string message=null) | |
Creates a new instance of application exception and assigns its values. More... | |
override void | GetObjectData (SerializationInfo info, StreamingContext context) |
ApplicationException | WithCode (string code) |
Sets a unique error code. More... | |
ApplicationException | WithCorrelationId (string correlationId) |
Sets a correlation id which can be used to trace this error through a call chain. More... | |
ApplicationException | WithCause (Exception cause) |
Sets a original error wrapped by this exception. More... | |
ApplicationException | WithStatus (int status) |
Sets a HTTP status code which shall be returned by REST calls. More... | |
ApplicationException | WithDetails (string key, object value) |
Sets a parameter for additional error details. This details can be used to restore error description in other languages. More... | |
ApplicationException | WithStackTrace (string stackTrace) |
Sets a stack trace for this error. This method returns reference to this exception to implement Builder pattern to chain additional calls. More... | |
ApplicationException | Wrap (Exception cause) |
Wraps another exception into specified application exception object. If original exception is of ApplicationException type it is returned without changes.Otherwise the original error is set as a cause to specified ApplicationException object. More... | |
Static Public Member Functions | |
static ApplicationException | WrapException (ApplicationException error, Exception cause) |
Wraps another exception into specified application exception object. If original exception is of ApplicationException type it is returned without changes.Otherwise the original error is set as a cause to specified ApplicationException object. More... | |
Public Attributes | |
string | BaseMessage => Message |
Protected Member Functions | |
ApplicationException (string message) | |
Creates a new instance of application exception with string message. More... | |
ApplicationException (SerializationInfo info, StreamingContext context) | |
Properties | |
string | Category [get, set] |
string | CorrelationId [get, set] |
string | Cause [get, set] |
string | Code [get, set] |
int | Status [get, set] |
StringValueMap | Details [get, set] |
new string | StackTrace [get, set] |
Private Attributes | |
string | _stackTrace |
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:
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.
PipServices3.Commons.Errors.ApplicationException.ApplicationException | ( | ) |
Creates a new instance of application exception.
|
protected |
Creates a new instance of application exception with string message.
message | a human-readable description of the error. |
PipServices3.Commons.Errors.ApplicationException.ApplicationException | ( | string | category = null , |
string | correlationId = null , |
||
string | code = null , |
||
string | message = null |
||
) |
Creates a new instance of application exception and assigns its values.
category | (optional) a standard error category. Default: Unknown |
correlationId | (optional) a unique transaction id to trace execution through call chain. |
code | (optional) a unique error code. Default: "UNKNOWN" |
message | (optional) a human-readable description of the error. |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithCause | ( | Exception | cause | ) |
Sets a original error wrapped by this exception.
This method returns reference to this exception to implement Builder pattern to chain additional calls.
cause | original error object |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithCode | ( | string | code | ) |
Sets a unique error code.
This method returns reference to this exception to implement Builder pattern to chain additional calls.
code | a unique error code |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithCorrelationId | ( | string | correlationId | ) |
Sets a correlation id which can be used to trace this error through a call chain.
This method returns reference to this exception to implement Builder pattern to chain additional calls.
correlationId | a unique transaction id to trace error through call chain |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithDetails | ( | string | key, |
object | value | ||
) |
Sets a parameter for additional error details. This details can be used to restore error description in other languages.
This method returns reference to this exception to implement Builder pattern to chain additional calls.
key | a details parameter key |
value | a details parameter name |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithStackTrace | ( | string | stackTrace | ) |
Sets a stack trace for this error. This method returns reference to this exception to implement Builder pattern to chain additional calls.
stackTrace | a stack trace where this error occured |
ApplicationException PipServices3.Commons.Errors.ApplicationException.WithStatus | ( | int | status | ) |
Sets a HTTP status code which shall be returned by REST calls.
This method returns reference to this exception to implement Builder pattern to chain additional calls.
status | an HTTP error code. |
ApplicationException PipServices3.Commons.Errors.ApplicationException.Wrap | ( | Exception | cause | ) |
Wraps another exception into specified application exception object. If original exception is of ApplicationException type it is returned without changes.Otherwise the original error is set as a cause to specified ApplicationException object.
cause | an original error object |
|
static |
Wraps another exception into specified application exception object. If original exception is of ApplicationException type it is returned without changes.Otherwise the original error is set as a cause to specified ApplicationException object.
error | an ApplicationException object to wrap the cause |
cause | an original error object |
string PipServices3.Commons.Errors.ApplicationException.BaseMessage => Message |
A human-readable error description (usually written in English)
|
getset |
Standard error category
|
getset |
Original error wrapped by this exception
|
getset |
A unique error code
|
getset |
A unique transaction id to trace execution throug call chain
|
getset |
A map with additional details that can be used to restore error description in other languages
|
getset |
Stack trace of the exception
|
getset |
HTTP status code associated with this error type