C# Interview Question #193
How would you handle errors consistently across an ASP.NET Core API?
Senior .NET Practical Scenarios Senior Advanced
Quick Interview Answer
Use centralized exception handling instead of duplicating broad try/catch blocks in every controller.
Detailed Explanation
Use centralized exception handling instead of duplicating broad try/catch blocks in every controller.
Expected validation and business failures should be represented clearly and mapped to appropriate HTTP status codes. Unexpected exceptions should be logged with structured context and normally mapped to a generic 500 response.
Problem Details is a standard format for HTTP API errors and can provide consistent fields such as status, title, detail, type, and trace identifiers.
Internal exception details, SQL statements, stack traces, secrets, and sensitive information should not be exposed to production clients.