Cabother.Exceptions 1.1.1

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

Cabother Exceptions

Biblioteca de apoio ao uso de exceptions customizadas

Nuget

https://www.nuget.org/packages/Cabother.Exceptions/
dotnet add package Cabother.Exceptions

Compatibilidade

O pacote é publicado com múltiplos targets, e cada projeto recebe automaticamente a versão mais adequada:

Target Atende
net10.0 .NET 10+
net8.0 .NET 8 e .NET 9
netstandard2.0 .NET 5, 6 e 7, .NET Core 2.0+ e .NET Framework 4.6.1+

Formato da mensagem

Todas as exceptions (exceto WebServiceException) herdam de BaseException e expõem a propriedade ErrorCode. A mensagem final segue o formato:

Construtor utilizado Mensagem gerada
(message) {message}
(message, errorCode) {errorCode} - {message}
(message, innerException) {message}: {innerMessage}
(message, errorCode, innerException) {errorCode} - {message}: {innerMessage}

Lista de Exceptions

Requests (Cabother.Exceptions.Requests)

Nome da Exception HTTP Descrição
BadRequestException 400 Servidor não pode ou não irá processar a requisição
UnauthorizedException 401 Requisição http não autorizada
ForbiddenException 403 Servidor entendeu o pedido, mas se recusa a autorizá-lo
NotFoundException 404 Recurso solicitado não existe
RequestTimeoutException 408 Requisição excedeu o tempo limite
ConflictException 409 Requisição conflita com o estado atual do recurso
PreconditionFailedException 412 Condição definida no cabeçalho da request não atendida
UnprocessableEntityException 422 Requisição válida, mas que não pode ser processada
TooManyRequestsException 429 Limite de requisições excedido (propriedade RetryAfter)
InternalServerErrorException 500 Erro interno no processamento da request
BadGatewayException 502 Servidor recebe uma resposta ruim de outro
ServiceUnavailableException 503 Serviço temporariamente indisponível
GatewayTimeoutException 504 Servidor upstream não respondeu a tempo
UnexpectedResponseException - Valor de uma resposta não é o esperado

Validações e domínio

Nome da Exception Namespace Descrição
ValidationException Cabother.Exceptions.Validations Dados de entrada inválidos, com erros por campo (Errors)
BusinessRuleException Cabother.Exceptions.Domains Violação de regra de negócio

Banco de dados (Cabother.Exceptions.Databases)

Nome da Exception Descrição Mensagem padrão
EntityNotFoundException Entidade não encontrada no banco de dados {entity} not found
EntityAlreadyExistsException Entidade já existe (ex.: chave duplicada) {entity} already exists
ConcurrencyException Entidade alterada por outro processo {entity} was modified by another process
RepositoryNotFoundException Repositório da entidade não encontrado {entity}'s repository not found

Configurações e ambiente

Nome da Exception Namespace Mensagem padrão
ConfigurationNotFoundException Cabother.Exceptions.Configurations Configuration key '{configurationKey}' not found.
InvalidConfigurationException Cabother.Exceptions.Configurations Configuration key '{configurationKey}' has an invalid value.
InvalidEnvironmentVariableException Cabother.Exceptions.Environments Environment variable '{VARIABLENAME}' don't parametrized.

Web services (Cabother.Exceptions.WebServices)

Nome da Exception Descrição
WebServiceException Erro em chamadas para web services (propriedades Method e ErrorCode)

Exemplos de uso

using Cabother.Exceptions.Databases;
using Cabother.Exceptions.Requests;
using Cabother.Exceptions.Validations;

// Mensagem com código de erro: "ORD-404 - Order 123 not found"
throw new NotFoundException("Order 123 not found", "ORD-404");

// Erros de validação agrupados por campo
throw new ValidationException(new Dictionary<string, string[]>
{
    ["Email"] = new[] { "Email is invalid" },
    ["Name"] = new[] { "Name is required" }
}, "VAL-001");

// Limite de requisições com tempo sugerido para nova tentativa
throw new TooManyRequestsException("Rate limit exceeded", "RL-001", TimeSpan.FromSeconds(30));

// Chave duplicada: "DB-001 - Customer already exists: {mensagem do erro original}"
catch (DbUpdateException ex)
{
    throw new EntityAlreadyExistsException("Customer", "DB-001", ex);
}

Extensões

O namespace Cabother.Exceptions.Extensions oferece métodos para converter e enriquecer exceções:

using Cabother.Exceptions.Extensions;

catch (Exception ex)
{
    ex.AddErrorCode("ERR-001");
    var code = ex.GetErrorCode();

    throw ex.ToInternalServerErrorException("ERR-500", "Failed to process order");
    // ou: ex.ToEntityNotFoundException("Order") / ex.ToConflictException("Order already processed")
}

<a href="https://www.buymeacoffee.com/cabother" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Cabother.Exceptions:

Package Downloads
Cabother.Validations.Helpers

Support library for object validation and primitive types

Cabother.Helpers

Support library for using custom methods

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 24,218 11/6/2026
1.1.0 155 11/6/2026
1.0.8 4,805 2/5/2022
1.0.7 43,702 5/16/2021
1.0.6 590 5/16/2021
1.0.5 1,308 4/29/2021
1.0.4 2,165 4/15/2021
1.0.3 2,509 4/14/2021
1.0.2 4,163 3/27/2021
1.0.1 726 3/27/2021
1.0.0 570 3/27/2021