CrCore.Exceptions 10.0.42

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package CrCore.Exceptions --version 10.0.42
                    
NuGet\Install-Package CrCore.Exceptions -Version 10.0.42
                    
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="CrCore.Exceptions" Version="10.0.42" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CrCore.Exceptions" Version="10.0.42" />
                    
Directory.Packages.props
<PackageReference Include="CrCore.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 CrCore.Exceptions --version 10.0.42
                    
#r "nuget: CrCore.Exceptions, 10.0.42"
                    
#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 CrCore.Exceptions@10.0.42
                    
#: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=CrCore.Exceptions&version=10.0.42
                    
Install as a Cake Addin
#tool nuget:?package=CrCore.Exceptions&version=10.0.42
                    
Install as a Cake Tool

Intro

A lightweight library for defining application errors, creating typed exceptions, and mapping external error codes into domain-specific exceptions.

This package contains only the core exception model and does not depend on ASP.NET Core.

Features

  • Typed application exceptions
  • Standard exception categories
  • Structured application errors (CrError)
  • External error mapping (ErrorMap)
  • Exception factory (ExceptionFactory)
  • No ASP.NET Core dependencies

Installation

dotnet add package CrCore.Exceptions

Error Model

Every application error is represented by CrError.

var error = new CrError("IdentityUserNotFound", "User was not found.");

Each error contains:

  • Code — stable identifier for clients.
  • Message — human-readable description.

Exception Categories

Applications should inherit from one of the predefined exception categories.

Available categories:

Exception Purpose
ValidationException Validation failures
UnauthorizedException Authentication required
ForbiddenException Access denied
NotFoundException Resource not found
ConflictException Resource conflict
UnprocessableException Business rule violation
InternalException Internal server error

Example:

public sealed class UserNotFoundException : NotFoundException
{
    public UserNotFoundException(Guid userId) : base(
        [new CrError("IdentityUserNotFound", $"User '{userId}' was not found.")],
        "User was not found.")
    {
    }
}

Usage:

throw new UserNotFoundException(userId);

ErrorMap

External systems usually expose their own error codes.

For example:

user_not_found

Those codes can be mapped into application errors.

ErrorMap errorMap = builder
    .Add(new ErrorRegistration(
        "user_not_found",
        [new CrError("IdentityUserNotFound", "User was not found.")]))
    .Build();

Resolving an external error:

if (errorMap.TryGet("user_not_found", out var errors))
{
    throw new UserNotFoundException(errors);
}

This keeps external service contracts isolated from the application domain.


ExceptionFactory

ExceptionFactory creates typed exceptions from registered external error codes.

Registration:

ExceptionFactory factory = builder
    .Add(new ExceptionRegistration(
        new ErrorRegistration(
            "invalid_grant",
            [new CrError("IdentityInvalidCredentials", "Invalid username or password.")]),
        errors => new InvalidCredentialsException(errors)))
    .Build();

Usage:

throw factory.Create("invalid_grant");

The factory only creates exceptions for registered error codes.

Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CrCore.Exceptions:

Package Downloads
CrCore.Exceptions.AspNet

ASP.NET Core integration for CR.Exceptions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.45 104 8/7/2026
10.0.44 94 8/5/2026
10.0.43 112 8/3/2026
10.0.42 109 8/1/2026
10.0.41 115 8/1/2026
10.0.40 109 7/30/2026
10.0.33 110 7/27/2026