Back to results for “Exceptions”
C# › Exception Handling

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

Advanced

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.