exception-handler

Implement global exception middleware and custom error responses for C# web APIs.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/kongliuli/VibeSkills --skill exception-handler-kongliuli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: exception-handler
Source: https://github.com/kongliuli/VibeSkills/tree/main/Skills/C%23/common/exception-handler
Command: npx skills add https://github.com/kongliuli/VibeSkills --skill exception-handler-kongliuli

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill standardizes how a C# project handles unexpected errors by providing a global middleware, a set of customizable exceptions, and a consistent error response. It helps ensure security, user-friendly messages, and unified logging across the codebase.

Core Features & Use Cases

  • Global exception middleware for ASP.NET Core applications.
  • Custom exception hierarchy with predefined error codes.
  • Unified error response model and structured logging.
  • Clear separation of concerns between business logic and error handling.

Quick Start

Install the middleware in your startup, register UseExceptionHandling, define a base CustomException with an ErrorCode, derive specific exceptions, and implement a shared ErrorCodes class to standardize responses.

Frequently Asked Questions about exception-handler

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

FAQPage Schema
How do I implement global exception handling in ASP.NET Core?

Global exception handling in ASP.NET Core is implemented by registering a middleware component in your startup pipeline. This skill uses UseExceptionHandling to intercept unhandled errors, enforce custom exception types, and return a consistent error response across all API endpoints.

How do I standardize error codes and custom exceptions in C# web APIs?

To standardize error codes in C# web APIs, you define a base CustomException class containing an ErrorCode property, derive specific exception types from it, and implement a shared ErrorCodes class. This enforces a unified error response model throughout the codebase.

What is the best way to separate business logic from error handling in C#?

The best way to separate business logic from error handling in C# is applying a centralized middleware approach. A global exception middleware intercepts failures, applying structured logging and traceability while keeping business logic focused only on core domain operations.

Does ASP.NET Core middleware support structured logging for unhandled exceptions?

Yes, ASP.NET Core middleware supports structured logging for unhandled exceptions. This skill applies a middleware-based approach that captures exceptions globally, enabling optional logging and traceability to ensure unified error tracking across services.

Can I use a custom exception hierarchy to enforce a uniform error response model?

Yes, you can use a custom exception hierarchy to enforce a uniform error response model. By creating a base CustomException with predefined error codes and deriving specific exceptions, the middleware standardizes all API failure responses consistently.

When should I not use global middleware for exception handling in C#?

You should not use global middleware for exception handling in C# when an endpoint requires highly specific, localized error trapping and custom recovery logic. Centralized middleware works best for standardizing general API failures rather than complex contextual retries.