ASP.NET Core Web API Interview Question #126

What is centralized exception handling in ASP.NET Core Web API?

Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced

Quick Interview Answer

Centralized exception handling catches unhandled exceptions at a common point in the HTTP pipeline instead of repeating try/catch blocks in every controller action. It is typically implemented with ASP.NET Core exception-handling middleware.

Detailed Explanation

Centralized exception handling catches unhandled exceptions at a common point in the HTTP pipeline instead of repeating try/catch blocks in every controller action. It is typically implemented with ASP.NET Core exception-handling middleware.

A centralized handler can log the exception and convert it into a safe, consistent API error response while keeping controllers focused on normal application flow.

Code Example

builder.Services.AddProblemDetails();

var app = builder.Build();

app.UseExceptionHandler();

app.MapControllers();