CrCore.Exceptions
10.1.0
Prefix Reserved
dotnet add package CrCore.Exceptions --version 10.1.0
NuGet\Install-Package CrCore.Exceptions -Version 10.1.0
<PackageReference Include="CrCore.Exceptions" Version="10.1.0" />
<PackageVersion Include="CrCore.Exceptions" Version="10.1.0" />
<PackageReference Include="CrCore.Exceptions" />
paket add CrCore.Exceptions --version 10.1.0
#r "nuget: CrCore.Exceptions, 10.1.0"
#:package CrCore.Exceptions@10.1.0
#addin nuget:?package=CrCore.Exceptions&version=10.1.0
#tool nuget:?package=CrCore.Exceptions&version=10.1.0
Intro
A high-performance .NET library to map external error codes into typed exceptions and translate infrastructure failures into domain exceptions.
Exception Factory
Use Case: Materialize string-based error codes from external APIs into strongly-typed exceptions.
{
"error": "invalid_grant"
}
Creating
public sealed class KeycloakInvalidGrantException : ValidationException
{
private static readonly ImmutableArray<CrError> _errors =
[new("IdentityInvalidGrant", "The authorization grant is invalid.")];
public KeycloakInvalidGrantException() : base(_errors) { }
}
Registration
var builder = new ExceptionFactoryBuilder()
.Map("invalid_grant", static () => new KeycloakInvalidGrantException());
var factory = builder.Build();
Receiving
if (factory.TryCreate(errorCode, out var exception)) throw exception;
Exception Translator
Use Case: Catch infrastructure failures and translate them into clean domain exceptions.
The mapping process traverses the exception type hierarchy.
Creating
public sealed class UserInvalidCredentialsException : ValidationException
{
private static readonly ImmutableArray<CrError> _errors = [new("UserInvalidCredentials")];
public UserInvalidCredentialsException(Exception? innerException = null) : base(_errors, DefaultMessage, innerException) { }
}
Registration
var builder = new ExceptionTranslatorBuilder()
.Map<KeycloakInvalidGrantException>(static ex => new UserInvalidCredentialsException(ex));
var translator = builder.Build();
Receiving
if (translator.TryTranslate(ex, out var translatedException))
{
throw translatedException;
}
Core
Base: All custom exceptions inherit from the CrException class.
It carries an ImmutableArray of structured error details (zero or more CrError instances):
record class CrError(string Code, string? Message = null);
Exception Categories
Inherit from semantic categories depending on the architectural context:
See the Categories folder for all available built-in exceptions.
| Product | Versions 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.