error-handling

Unify .NET error handling with domain exceptions, ProblemDetails, and gRPC RpcException mapping.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill error-handling-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: error-handling
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/core/error-handling
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill error-handling-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardizes error handling across domain exceptions, ProblemDetails, and RpcException mapping for .NET services.

Core Features & Use Cases

  • Domain exception hierarchy including DomainException, NotFoundException, ValidationException, and ConcurrencyException to express precise failure modes.
  • IProblemDetailsProvider-compatible exceptions to produce rich REST error responses with proper Type, Title, Status, and Detail.
  • gRPC interceptor (ApplicationExceptionInterceptor) that translates DomainException instances into RpcException with problem-details-bin metadata and status mapping.
  • Centralized status-code mapping between HTTP status codes and gRPC StatusCode for consistent client experiences.
  • Structured error logging with contextual properties (e.g., ErrorCode, Entity names, identifiers) to enable effective traceability.
  • Best-practice guidance and anti-patterns to avoid generic, uninformative errors.

Quick Start

Install and wire the error-handling primitives into your .NET service, register the interceptor, and enforce the ProblemDetails-based responses for REST and gRPC callers.

Frequently Asked Questions about error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize error handling for domain exceptions across REST and gRPC in .NET?

Standardize .NET error handling by implementing a DomainException base class and mapping it to ProblemDetails for REST and RpcException for gRPC. This unifies responses through centralized status-code mapping and structured logging across both protocols.

What is the best way to map domain exceptions to gRPC RpcException with ProblemDetails?

The best way to map domain exceptions to gRPC RpcException is using an ApplicationExceptionInterceptor. This interceptor catches domain exceptions, sets the correct gRPC StatusCode, and attaches problem-details-bin metadata for client-friendly responses.

How does ProblemDetails work with custom domain exceptions in a .NET API?

ProblemDetails works with custom domain exceptions by implementing an IProblemDetailsProvider interface. This allows exceptions like NotFoundException or ValidationException to generate rich REST error responses containing Type, Title, Status, and Detail fields.

Can I use structured logging to capture specific error codes and entity identifiers during exception handling?

Yes, structured logging captures contextual properties like ErrorCode, Entity names, and identifiers during exception handling. This enables effective traceability by appending these details to logs when domain exceptions are thrown and processed.

What are common anti-patterns when implementing error handling for .NET services?

Common error handling anti-patterns include throwing generic, uninformative exceptions without specific domain context or structured logging. This prevents clients from understanding failures and hinders debugging due to missing error codes and mapped status details.

Do I need separate exception hierarchies for validation and concurrency failures in .NET?

Yes, using separate exception types like ValidationException and ConcurrencyException within a DomainException hierarchy expresses precise failure modes. This allows distinct status-code mapping and accurate ProblemDetails generation for each specific error.