ASP.NET Core MVC Interview Question #139
What is the difference between exception handling and status-code handling?
Dependency Injection, Services, Error Handling, Logging & Performance Senior Advanced
Quick Interview Answer
Exception handling deals with failures represented by thrown exceptions. Status-code handling deals with completed responses such as 404 or 403 that may not involve an exception at all.
Detailed Explanation
Exception handling deals with failures represented by thrown exceptions. Status-code handling deals with completed responses such as 404 or 403 that may not involve an exception at all.
An application can use exception-handling middleware for unexpected failures and status-code pages or dedicated endpoints for user-friendly HTTP error responses. A 404 should not normally be manufactured by throwing a general exception.
Code Example
app.UseExceptionHandler("/Home/Error");
app.UseStatusCodePagesWithReExecute(
"/Home/StatusCode",
"?code={0}");