CrCore.Exceptions 10.0.43

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.43
                    
NuGet\Install-Package CrCore.Exceptions -Version 10.0.43
                    
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.43" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CrCore.Exceptions" Version="10.0.43" />
                    
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.43
                    
#r "nuget: CrCore.Exceptions, 10.0.43"
                    
#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.43
                    
#: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.43
                    
Install as a Cake Addin
#tool nuget:?package=CrCore.Exceptions&version=10.0.43
                    
Install as a Cake Tool

Intro

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

This package contains only the core exception model and has no ASP.NET Core dependencies.

Features

  • Typed application exceptions
  • Standard exception categories
  • Structured application errors (CrError)
  • Error code → exception mapping (ExceptionFactory)
  • Exception → exception translation (ExceptionTranslator)
  • 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 intended for clients.
  • Message — human-readable error 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()
        : base(
        [
            new CrError(
                "IdentityUserNotFound",
                "User was not found.")
        ])
    {
    }
}

Usage:

throw new UserNotFoundException();

ExceptionFactory

External APIs often return string error codes.

For example:

invalid_grant

ExceptionFactory maps those codes to typed exceptions.

Registration:

ExceptionFactory factory = new ExceptionFactoryBuilder()
    .Map(
        "invalid_grant",
        static () => new InvalidCredentialsException())
    .Build();

Usage:

throw factory.Create("invalid_grant");

This keeps external service contracts isolated from your application.


ExceptionTranslator

Infrastructure exceptions are often not suitable for the application layer.

ExceptionTranslator converts one exception type into another.

Registration:

ExceptionTranslator translator = new ExceptionTranslatorBuilder()
    .Map<KeycloakUserNotFoundException>(
        static () => new UserNotFoundException())
    .Build();

Usage:

catch (KeycloakUserNotFoundException ex)
{
    throw translator.Translate(ex);
}

This allows infrastructure-specific exceptions to remain inside the infrastructure layer while exposing domain-specific exceptions to the rest of the application.

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