Advertisement
Advanced C#, Exception Handling

What is the recommended strategy for exceptions in a layered/enterprise app?

Short answer

Throw specific exceptions in lower layers, don't swallow them, translate to a consistent response at the boundary (middleware/ProblemDetails), and log with context. Avoid using exceptions for control flow.

Save C# mock interview
Advertisement
AModel answer
Throw specific exceptions in lower layers, don't swallow them, translate to a consistent response at the boundary (middleware/ProblemDetails), and log with context. Avoid using exceptions for control flow.
app.UseExceptionHandler();  // central translation to ProblemDetails
Real-world example
One middleware converts domain and unexpected exceptions into consistent JSON errors for all API clients.