Roadmap › 1. .NET › Step 22
Err

Exception Handling & Custom Error Handling in .NET — Every Way, Every App Type

Exceptions from first principles to production — try/catch/finally, filters, rethrowing, custom exception hierarchies, exceptions vs Result pattern, async and parallel exceptions, global handlers (AppDomain, TaskScheduler, Application_Error), every way to handle errors in Web Forms, MVC 5, Web API 2, ASP.NET Core MVC and Web API (middleware, exception filters, IExceptionHandler, ProblemDetails, UseStatusCodePages), Blazor error boundaries, background services, SQL and HTTP error handling, retries with Polly, custom error pages, error codes and correlation ids.
Quick revision for interview day. Print it or save it as a PDF.

Rules

Validate early · catch specific · throw; · wrap with inner · using for cleanup · no empty catch · no exceptions for flow · global handler at boundaries · log once with correlation id · friendly messages, no internals.

ASP.NET Core

AddProblemDetails + AddExceptionHandler<T> + UseExceptionHandler() · UseStatusCodePages(WithReExecute) · exception filters for MVC · [ApiController] 400s · developer page only in Development.

.NET Framework

Web Forms: try/catch → Page_Error → Application_Error → customErrors/httpErrors · MVC 5: OnException → [HandleError]/IExceptionFilter → Application_Error · Web API 2: IExceptionHandler/IExceptionLogger.

Status mapping

Validation 400 · auth 401/403 · not found 404 · conflict/duplicate/concurrency 409 · business rule 422 · rate limit 429 · bug/unknown 500 · dependency down 502/503 · timeout 504.

Async & process

await rethrows first exception · WhenAll → check InnerExceptions · avoid async void · BackgroundService: try/catch per iteration · AppDomain.UnhandledException / TaskScheduler.UnobservedTaskException for last-chance logging.