---
title: Construct SAIF exceptions
summary: Create the library's exception types used by implementation libraries for application-level errors.
status: draft
owner: Framework.NCore maintainers
last_reviewed: 2026-10-02
library: SAIF.NetCore.ServiceContracts
reference_type: package
operation_id: OP-05
trigger: Implementation-library code throws `new SAIFException(message[, inner])` or `new HttpStatusCodeException(message[, inner])`.
---

# 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](../business-rules.md#br-009-httpstatuscodeexception-defaults-to-text-plain-content-type))
3. `SAIFException.LogDetails` remains `null` by default until the thrower assigns it.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
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.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## 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`
