Cirreum.Exceptions 1.0.1

dotnet add package Cirreum.Exceptions --version 1.0.1
                    
NuGet\Install-Package Cirreum.Exceptions -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cirreum.Exceptions" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cirreum.Exceptions" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Cirreum.Exceptions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cirreum.Exceptions --version 1.0.1
                    
#r "nuget: Cirreum.Exceptions, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cirreum.Exceptions@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cirreum.Exceptions&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Cirreum.Exceptions&version=1.0.1
                    
Install as a Cake Tool

Cirreum.Exceptions

NuGet Version NuGet Downloads License .NET

Application exception types for the Cirreum Framework

Overview

Cirreum.Exceptions provides a standardized set of application-level exception types that map directly to HTTP status codes. These exceptions serve as the foundation for consistent error handling across all Cirreum libraries and applications.

This library is part of the Base layer of the Cirreum ecosystem, meaning it has zero dependencies on other Cirreum packages and is fully AOT-compatible.

Features

  • Zero Dependencies - No external package references
  • AOT Compatible - Full Native AOT support with IsAotCompatible=true
  • HTTP-Aligned - Exception types map directly to HTTP status codes
  • RFC 7807 Support - ExceptionModel for Problem Details serialization
  • Validation Models - FailureModel for structured validation errors

Exception Types

Exception HTTP Status Use Case
BadRequestException 400 Malformed or invalid request data
UnauthorizedException 401 Missing or invalid authentication
ForbiddenException 403 Authenticated but not authorized
NotFoundException 404 Resource not found
ConflictException 409 Resource state conflict
ConcurrencyException 409 Optimistic concurrency violation
ServerException 500 Internal server error

Installation

dotnet add package Cirreum.Exceptions

Usage

Throwing Exceptions

using Cirreum.Exceptions;

// Resource by Id not found
throw new NotFoundException(userId);

// Authorization failure
throw new ForbiddenException("You do not have access to this resource");

// Validation failure
throw new BadRequestException("Email address is invalid");

// Concurrency conflict
throw new ConcurrencyException(entityId);

ExceptionModel for Problem Details

The ExceptionModel class provides RFC 7807 Problem Details support:

using Cirreum.Exceptions;

var model = new ExceptionModel {
    Type = "https://example.com/errors/not-found",
    Title = "Resource Not Found",
    Status = 404,
    Detail = "The requested user was not found",
    Instance = "/api/users/123"
};

// Serialize to application/problem+json
var json = JsonSerializer.Serialize(model);

Extension data is supported via JsonExtensionData:

var model = new ExceptionModel {
    Title = "Validation Failed",
    Status = 400,
    Extensions = new Dictionary<string, JsonElement> {
        ["errors"] = JsonSerializer.SerializeToElement(validationErrors)
    }
};

FailureModel for Validation Errors

using Cirreum.Exceptions;

var failure = new FailureModel {
    PropertyName = "Email",
    ErrorMessage = "Email address is not valid",
    ErrorCode = "EmailValidator",
    AttemptedValue = "not-an-email"
};

Fatal Exception Detection

The IsFatal extension method identifies exceptions that should not be caught:

using System;

try {
    // ... operation
}
catch (Exception ex) when (!ex.IsFatal()) {
    // Safe to handle - not OOM, StackOverflow, or ThreadAbort
    logger.LogError(ex, "Operation failed");
}

Integration

ASP.NET Core

Cirreum.Exceptions integrates seamlessly with ASP.NET Core's exception handling:

app.UseExceptionHandler(builder => {
    builder.Run(async context => {
        var exception = context.Features.Get<IExceptionHandlerFeature>()?.Error;

        var (statusCode, model) = exception switch {
            NotFoundException ex => (404, ex.ToExceptionModel()),
            ForbiddenException ex => (403, ex.ToExceptionModel()),
            BadRequestException ex => (400, ex.ToExceptionModel()),
            _ => (500, new ExceptionModel { Title = "Internal Server Error", Status = 500 })
        };

        context.Response.StatusCode = statusCode;
        context.Response.ContentType = "application/problem+json";
        await context.Response.WriteAsJsonAsync(model);
    });
});

Cirreum Ecosystem

This library provides the exception foundation for:

  • Cirreum.Core - Application core uses these exception types
  • Cirreum.Persistence.Sql - Database operations throw these exceptions
  • Cirreum.Persistence.Azure - Azure storage operations use these exceptions
  • Cirreum.Runtime - Runtime exception handling and middleware

Design Principles

HTTP-First Design

Exception types are designed around HTTP semantics, making it trivial to translate application errors to appropriate HTTP responses.

AOT Compatibility

All types are fully compatible with Native AOT compilation. The ExceptionModel.Extensions property uses IDictionary<string, JsonElement> instead of object to ensure AOT-safe serialization.

Zero Dependencies

This package has no external dependencies, keeping the dependency graph clean for Base layer consumers.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Cirreum Foundation Framework Layered simplicity for modern .NET

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Cirreum.Exceptions:

Package Downloads
Cirreum.Core

The Cirreum Application Core libary

Cirreum.Persistence.Sql

Dapper persistence provider for Cirreum framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 994 1/21/2026
1.0.0 953 1/4/2026