CrCore.Exceptions
10.0.45
Prefix Reserved
dotnet add package CrCore.Exceptions --version 10.0.45
NuGet\Install-Package CrCore.Exceptions -Version 10.0.45
<PackageReference Include="CrCore.Exceptions" Version="10.0.45" />
<PackageVersion Include="CrCore.Exceptions" Version="10.0.45" />
<PackageReference Include="CrCore.Exceptions" />
paket add CrCore.Exceptions --version 10.0.45
#r "nuget: CrCore.Exceptions, 10.0.45"
#:package CrCore.Exceptions@10.0.45
#addin nuget:?package=CrCore.Exceptions&version=10.0.45
#tool nuget:?package=CrCore.Exceptions&version=10.0.45
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
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 innerException => new UserNotFoundException(innerException))
.Build();
Usage:
catch (Exception 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 | 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 (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.