Skip to content

Construct SAIF exceptions

Create the library's exception types used by implementation libraries for application-level errors. This operation is triggered when implementation-library code throws new SAIFException(message[, inner]) or new HttpStatusCodeException(message[, inner]).

Field Value
Operation ID OP-05
Trigger Implementation-library code throws new SAIFException(message[, inner]) or new HttpStatusCodeException(message[, inner]).
Inputs message (string), optional inner (Exception)
Outputs A SAIFException or HttpStatusCodeException instance ready to be thrown.
Primary components SAIFException..ctor, HttpStatusCodeException..ctor
Entry point src/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/SAIFException.cs

Steps

  1. Pass message/inner to the System.Exception base constructor.
  2. For HttpStatusCodeException, ContentType initializes to "text/plain" and StatusCode stays at the int default 0 until the consumer sets it. (BR-009)
  3. SAIFException.LogDetails remains null by default until the thrower assigns it.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Throw site constructs exception]) --> Base["Call System.Exception base constructor<br>with message and inner"]
    Base --> IsHttp{HttpStatusCodeException?}
    IsHttp -->|Yes| DefaultContentType["ContentType defaults to text/plain, StatusCode defaults to 0"]
    IsHttp -->|No| LogDetails[LogDetails remains null until assigned]
    DefaultContentType --> End([Exception ready to throw])
    LogDetails --> End

Failure and edge-case behavior

  • No validation occurs; message may be null or empty and both exception types construct successfully.

Sources

  • src/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/SAIFException.cs
  • src/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/SAIF.NetCore.ServiceContracts/HttpStatusCodeException.cs