GM.Exceptions 1.2.1

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

<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.Exceptions/master/icon.png" alt="GM.Exceptions" width="140" height="140" /> </p>

GM.Exceptions

CI NuGet License: MIT

A small collection of reusable exception types for .NET apps: a common base exception, HTTP-style domain exceptions (not found, bad request, already exists, …), and a FluentValidation-aware ValidationException. Messages can be localized from .resx resources. Targets net10.0.

Install

dotnet add package GM.Exceptions

Exception types

Type Purpose
CustomException Base type for all the others (derives from Exception).
NotFoundException An entity/relationship wasn't found.
AlreadyExistsException A unique value already exists.
BadRequestException Invalid input / bad request.
InternalServerException Unexpected server-side failure.
DeleteException A delete couldn't be completed.
ValidationException Carries per-field validation errors (see below).
FileServiceException, IdentityServiceException, LanguageNotDefinedException, RefreshTokenException Common service/infra failures.
throw new NotFoundException("User", "Id", id);
throw new BadRequestException("The 'from' date must be before 'to'.");

Catch the base type to handle any of them:

catch (CustomException ex) { /* map to an HTTP response, log, etc. */ }

Validation errors

ValidationException turns FluentValidation failures into a per-field dictionary, and its message is JSON:

var result = validator.Validate(request);
if (!result.IsValid)
    throw new ValidationException(result.Errors);

// ex.Failures => { "Email": ["'Email' is not a valid email."], ... }

Localized messages

The resource-based exceptions (NotFoundException, AlreadyExistsException, DeleteException, …) look up their message by key (NotFoundError, AlreadyExistsError, DeleteError, …) from a ResourceManager found in your loaded assemblies. Add a .resx with those keys (and culture variants) and the messages are formatted with the supplied arguments. If no matching resource is found, the exception falls back to a !!Key!! placeholder so nothing crashes.

Contributing & releases

Versioning is automated from Conventional Commits — see CONTRIBUTING.md.

License

MIT — see LICENSE.

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.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on GM.Exceptions:

Package Downloads
GM.API.Application

Application-layer building blocks for the GM.API stack: GM.Mediator wiring plus validation and performance pipeline behaviours, and paged-list models. Part of the GM.API family.

GM.API

An opinionated ASP.NET Core Web API starter for .NET. A single AddGMAPI/UseGMAPI pair wires up controllers, CORS, API versioning, Swagger docs, FluentValidation, Serilog, and middlewares for exception handling, request logging (with sensitive-data masking) and request localization. Bundles the GM.API.* companion packages.

GM.API.Middlewares

ASP.NET Core middlewares for the GM.API stack: exception handling (ProblemDetails), request logging with sensitive-data masking, and request localization. Part of the GM.API family.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 27 7/30/2026
1.2.0 64 7/29/2026
1.1.0 141 7/2/2026
1.0.4 321 7/9/2025
1.0.3 223 7/9/2025
1.0.2 378 6/12/2025
1.0.1 362 6/12/2025
1.0.0 234 5/18/2025