Problemize provides a robust and extensible framework for centralized exception handling in .NET Web APIs. It standardizes error responses using ProblemDetails and integrates seamlessly with ASP.NET Core.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/FloppyShelf/Problemize/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Install the FloppyShelf.Problemize package from NuGet:Setup
Configure services
Add exception handling services to your dependency injection container:
Program.cs
The
UseExceptionHandling() method automatically configures:- ProblemDetails with request metadata (instance, requestId, activityId)
- Default status code mapping for common exceptions
- Global exception handler service
Complete example
Here’s a complete working example:Response format
All exceptions are automatically converted to standardized RFC 9457 Problem Details responses:The exception type name (e.g.,
ValidationException, KeyNotFoundException)A short, human-readable summary of the problem type
The HTTP status code generated by the origin server
The exception message providing specific details about this occurrence
The HTTP method and path of the request that caused the error
The unique identifier for this request (TraceIdentifier)
The distributed tracing activity ID, if available
Built-in status code mappings
Problemize automatically maps common .NET exceptions to appropriate HTTP status codes:View all exception mappings
View all exception mappings
| Exception Type | Status Code | Description |
|---|---|---|
ValidationException | 400 | Bad Request |
ArgumentNullException | 400 | Bad Request |
ArgumentOutOfRangeException | 400 | Bad Request |
InvalidOperationException | 400 | Bad Request |
FormatException | 400 | Bad Request |
OverflowException | 400 | Bad Request |
NullReferenceException | 400 | Bad Request |
UnauthorizedAccessException | 401 | Unauthorized |
KeyNotFoundException | 404 | Not Found |
FileNotFoundException | 404 | Not Found |
DirectoryNotFoundException | 404 | Not Found |
NotSupportedException | 405 | Method Not Allowed |
TimeoutException | 408 | Request Timeout |
NotImplementedException | 501 | Not Implemented |
OutOfMemoryException | 500 | Internal Server Error |
StackOverflowException | 500 | Internal Server Error |
| All other exceptions | 500 | Internal Server Error |
Best practices
Use specific exceptions
Throw specific exception types (e.g.,
KeyNotFoundException) instead of generic Exception to get accurate HTTP status codesMeaningful error messages
Provide clear, actionable error messages in your exceptions - they become the
detail field in the responseValidationException for validation
Use
ValidationException for input validation errors to get properly formatted validation problem detailsEarly middleware placement
Register
UseExceptionHandling() early in your middleware pipeline to catch all exceptionsNext steps
Custom status codes
Learn how to create custom exception-to-status-code mappings
Custom exceptions
Create domain-specific exceptions for your application