Fermat.Domain.Exceptions 0.0.1

dotnet add package Fermat.Domain.Exceptions --version 0.0.1
                    
NuGet\Install-Package Fermat.Domain.Exceptions -Version 0.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="Fermat.Domain.Exceptions" Version="0.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Fermat.Domain.Exceptions" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Fermat.Domain.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 Fermat.Domain.Exceptions --version 0.0.1
                    
#r "nuget: Fermat.Domain.Exceptions, 0.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 Fermat.Domain.Exceptions@0.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=Fermat.Domain.Exceptions&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Fermat.Domain.Exceptions&version=0.0.1
                    
Install as a Cake Tool

Fermat.Domain.Exceptions

Fermat.Exceptions is a library that provides a comprehensive exception handling system for .NET applications. It includes predefined exception types and interfaces for standardized error handling across your application.

Features

  • Predefined exception types for common scenarios
  • Standardized exception interfaces
  • HTTP status code mapping
  • Validation error handling
  • Business rule violation handling
  • Entity not found handling
  • User-friendly error messages
  • Correlation ID support

Installation

   dotnet add package Fermat.Domain.Exceptions

Content

Exception Types

Base Exception
  • AppException: Base exception class with common properties and behaviors
    • Error code
    • Error details
    • Timestamp
    • Correlation ID
Domain Exceptions
  • AppEntityNotFoundException: Thrown when an entity is not found

    • Entity type
    • Entity ID
    • Search criteria
    • Custom message
  • AppBusinessException: Thrown when business rules are violated

    • Business rule code
    • Business rule message
    • Additional context
  • AppValidationException: Thrown when validation fails

    • Validation errors collection
    • Field-specific errors
    • Custom validation messages
  • AppAuthorizationException: Thrown when authorization fails

    • Required permissions
    • Access denied reason
    • User context
  • AppUserFriendlyException: Thrown for user-friendly error messages

    • User-friendly message
    • Technical details (optional)
    • Suggested actions

Exception Interfaces

Core Interfaces
  • IHasErrorCode: Interface for exceptions with error codes
  • IHasErrorDetails: Interface for exceptions with detailed error information
  • IHasTimestamp: Interface for exceptions with timestamp information
  • IHasCorrelationId: Interface for exceptions with correlation ID tracking
  • IHasStatusCode: Interface for exceptions with HTTP status codes
  • IHasValidationErrors: Interface for exceptions with validation errors

Usage

Basic Exception Usage

// Entity not found
throw new AppEntityNotFoundException(typeof(User), userId);

// Business rule violation
throw new AppBusinessException("USER_INACTIVE", "User account is inactive");

// Authorization error
throw new AppAuthorizationException("ADMIN_REQUIRED", "Admin access required");

// User-friendly error
throw new AppUserFriendlyException(
    "Unable to process your request at this time",
    "Please try again later or contact support"
);

AppException Methods

AppException provides a fluent API for configuring exception properties:

// Basic usage
throw new AppBusinessException("User account is inactive")
    .WithCode("USER:INACTIVE:1001")
    .WithDetails("Account was deactivated by admin")
    .WithStatusCode(400)
    .WithCorrelationId("corr-123")
    .WithData("UserId", userId)
    .AppendData(new Dictionary<string, object>
    {
        { "LastLoginDate", lastLoginDate },
        { "DeactivationReason", reason }
    });
Available Methods
  • WithData(string name, object value): Adds a single key-value pair to exception data
  • AppendData(IDictionary<string, object> data): Adds multiple key-value pairs to exception data
  • WithCode(string code): Sets the error code
  • WithDetails(string details): Sets the error details
  • WithStatusCode(int statusCode): Sets the HTTP status code
  • WithCorrelationId(string correlationId): Sets the correlation ID

Features

  • Standardized exception handling
  • HTTP status code mapping
  • Validation error collection
  • Business rule violation handling
  • Entity not found handling
  • User-friendly messages
  • Correlation tracking
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 was computed.  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 was computed.  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.
  • net8.0

    • No dependencies.

NuGet packages (2)

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

Package Downloads
Fermat.EntityFramework.Shared

A set of shared extensions for Fermat Entity Framework projects.

Fermat.Cqrs.Behaviors

A library that provides behaviors for CQRS (Command Query Responsibility Segregation) patterns in .NET applications, enhancing command and query processing with features like validation, logging, and retry policies.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1 127 7/27/2025