I have a question regarding whether exception classes should contain business rules, for example, supposing I have several exception methods, and in these exception methods I end up populating entity information to be saved in the database. For example
public class CustomException : Exception
{
public CustomException(IActionResult httpResult, string? taskType = null, string? accessControlExposeHeaders = null)
{
HttpResult = httpResult;
if (taskType != null)
Data["some-header"] = taskType;
if (accessControlExposeHeaders != null)
Data["Access-Control-Expose-Headers"] = accessControlExposeHeaders;
}
internal static CustomException ThrowCustomException()
{
// Here I make manipulations of the entity to be saved in the database, for example, error status, status code to be saved and so on.
}
}
Or would it be better to create a validation class, and in this class, do the necessary manipulations, and then call the exception class just by passing the necessary constructor?
I've read the links below, but I don't quite understand them