Lyo.Exceptions
1.0.0
dotnet add package Lyo.Exceptions --version 1.0.0
NuGet\Install-Package Lyo.Exceptions -Version 1.0.0
<PackageReference Include="Lyo.Exceptions" Version="1.0.0" />
<PackageVersion Include="Lyo.Exceptions" Version="1.0.0" />
<PackageReference Include="Lyo.Exceptions" />
paket add Lyo.Exceptions --version 1.0.0
#r "nuget: Lyo.Exceptions, 1.0.0"
#:package Lyo.Exceptions@1.0.0
#addin nuget:?package=Lyo.Exceptions&version=1.0.0
#tool nuget:?package=Lyo.Exceptions&version=1.0.0
Lyo.Exceptions
Custom exception types and argument validation helpers for the Lyo library suite. Used across all Lyo packages for consistent error handling and validation.
Features
- ArgumentHelpers – Argument validation with
ThrowIfNull,ThrowIfNullOrWhiteSpace,ThrowIfNullOrEmpty,ThrowIf,ThrowIfNotInRange,ThrowIfFileNotFound,ThrowIfNullReturn(for constructor chaining), plusThrowIfEmpty(GUIDs),ThrowIfDefault(structs such asDateTime),ThrowIfNotDefined(enum casts), andThrowIfIndexOutOfRange - UriHelpers – URI validation with
GetValidWebUri,ThrowIfInvalidUri,ThrowIfInvalidAbsoluteUri - OperationHelpers – Operation/state validation (
ThrowIf,ThrowIfNull,ThrowIfNullOrWhiteSpace, stream checks, disposition/cancellation/not-supported) plus numeric parity withArgumentHelpers:ThrowIfNotInRange(scalar,DateTime,TimeSpan, array lengths),ThrowIfGreaterThan,ThrowIfGreaterThanOrEqual,ThrowIfLessThan,ThrowIfLessThanOrEqual,ThrowIfZero, sign helpers,ThrowIfEqual,ThrowIfNotEqual - OrThrow / StringOr – Fluent
string?.Or/.OrIfWhiteSpacechains and terminals (OrThrowInvalidOperation,OrThrow(Func<…>), etc.) plus genericOrThrowInvalidOperation/OrThrowunwraps—implemented here so callers do not pull inLyo.Commonfor throw-only ergonomics - FileHelpers – File name validation with
ThrowIfFileNameInvalid,GetValidFileName, and path-prefix safety helpersNormalizePathPrefix,ThrowIfPathPrefixTraversal,NormalizeAndValidatePathPrefix(shared by every Lyo.FileStorage backend's save/direct-upload/diagnostics paths) - FormatHelpers – Format validation throwing
InvalidFormatException(ThrowIfInvalidGuid,GetValidGuid, hex color,ThrowIfInvalidFormatwith custom regex,ThrowIfInvalidPort/IsValidPortfor 1–65535,ThrowIfNotInRangefor numeric options checks, etc.) - ConfigurationHelpers – Configuration validation throwing
ConfigurationException(ThrowIf,ThrowIfNull,ThrowIfNullOrWhiteSpace) with caller-expression setting names - ExceptionThrower – File/directory existence and accessibility (
ThrowIfDirectoryNotFound,ThrowIfFileNotAccessible,ThrowIfDirectoryNotAccessible) - Custom exceptions –
ArgumentOutsideRangeException,InvalidFormatException,ConfigurationException,HttpException(base forBadRequestException,UnauthorizedException,ForbiddenException,NotFoundException,ConflictException,GoneException,UnprocessableEntityException,RateLimitExceededException,ServiceUnavailableException,GatewayTimeoutException), and more - HttpException extras – every
HttpExceptioncarries an optional machine-readableErrorCode(init-only) and anIsTransientflag (true for 429/503/504) that retry policies can use as a single predicate;HttpExceptions.FromStatusCode(statusCode, message)maps raw status codes to the dedicated types (orGenericHttpExceptionfor unknown codes), andNotFoundException/ConflictException/ForbiddenException/GoneExceptionexposeForResource(name, id)factories that always set the resource properties (avoiding thenew NotFoundException("User", null)constructor-overload trap) - ValidationErrorsBuilder – accumulates field-level errors (
Add,AddIf,AddRange) and throws a singleValidationExceptionviaThrowIfAny()only when errors exist
Examples
Quick Start
using Lyo.Exceptions;
// Argument validation
public void Process(string name, byte[] data)
{
ArgumentHelpers.ThrowIfNullOrWhiteSpace(name);
ArgumentHelpers.ThrowIfNullOrEmpty(data);
// ...
}
// Constructor chaining
public MyService(IOptions options, ILogger logger)
: base(ArgumentHelpers.ThrowIfNullReturn(options), logger)
{
}
// URI validation
var uri = UriHelpers.GetValidWebUri(url);
// Operation state (builder/build validation)
OperationHelpers.ThrowIfNull(_data, "Data must be specified using WithData()");
OperationHelpers.ThrowIf(_count == 0, "At least one item is required");
// New guards
ArgumentHelpers.ThrowIfEmpty(tenantId); // Guid.Empty
ArgumentHelpers.ThrowIfDefault(createdAt); // default(DateTime)
ArgumentHelpers.ThrowIfNotDefined((DayOfWeek)value); // undefined enum cast
ArgumentHelpers.ThrowIfIndexOutOfRange(index, items.Count);
// HTTP exceptions with error codes and resource factories
throw NotFoundException.ForResource("User", userId);
throw new ConflictException("Order already submitted.") { ErrorCode = "order.already_submitted" };
var ex = HttpExceptions.FromStatusCode(503, "Upstream unavailable."); // ex.IsTransient == true
// Accumulate validation errors, throw once
var errors = new ValidationErrorsBuilder()
.AddIf(string.IsNullOrWhiteSpace(req.Email), nameof(req.Email), "Email is required.")
.AddIf(req.Age < 0, nameof(req.Age), "Age must be positive.");
errors.ThrowIfAny();
| Product | Versions 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 was computed. 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. |
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
NuGet packages (117)
Showing the top 5 NuGet packages that depend on Lyo.Exceptions:
| Package | Downloads |
|---|---|
|
Lyo.Common
Common utilities, extensions, enums, JSON converters, and helper classes for the Lyo library suite. |
|
|
Lyo.Result
Result, Error, Option, and validation primitives for the Lyo library suite. |
|
|
Lyo.Metrics
Metrics collection and reporting library with support for counters, timers, and snapshots. Provides a pluggable metrics interface for integration with various metrics backends. |
|
|
Lyo.Hashing
Digests, hex encoding, hashing streams, non-cryptographic checksums (CRC/Adler), lightweight file fingerprints (non-security), and optional hashing service. |
|
|
Lyo.Query.Models
Query models for building and representing queries - QueryNode, QueryRequest, ConditionNode, SortBy, builders. Shared by Lyo.Query and Lyo.Api. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 357 | 8/16/2026 |