The Slothful CRUD library provides a robust mechanism for handling exceptions through the implementation of the IExceptionHandler interface. This allows you to customize the way exceptions are handled and ensure that meaningful error information is returned to the client.

Exception Handling Interface

To customize exception handling, you need to implement the IExceptionHandler interface:

public interface IExceptionHandler
    SlothProblemDetails HandleError(Exception exception);


The SlothProblemDetails class extends the standard ProblemDetails class to include additional properties for more detailed error reporting:

public class SlothProblemDetails : ProblemDetails
    public Guid ProblemId { get; set; }
    public string Code { get; set; }

Additional Fields

  • ProblemId: A unique identifier for the problem instance. This helps in tracking and correlating errors, especially in distributed systems or when logging errors for further analysis.
  • Code: A specific error code that categorizes the type of error. This can be used to programmatically handle different types of errors and provide more granular error information to the client.

How It Works

When an exception occurs, the IExceptionHandler implementation processes the exception and returns a SlothProblemDetails object. This object contains detailed information about the error, including a unique problem ID, an error code, and a human-readable message.

For a general overview of problem handling, refer to the Problem Handling section.

Importance of Custom Exception Handling

Customizing exception handling allows you to:

  • Provide Detailed Error Information: Return meaningful error messages to the client, making it easier to diagnose and resolve issues.
  • Maintain Consistency: Ensure that all exceptions are handled uniformly across your application.
  • Enhance Security: Hide sensitive information from error messages that are exposed to clients.

By implementing the IExceptionHandler interface, you can tailor the exception handling behavior of your Slothful CRUD application to meet your specific needs. This flexibility ensures that your application can handle errors gracefully and provide useful feedback to clients.