Inside my business logic, I have something like a pipeline with multiple actions. Each action wrapped into try/catch and can handle exceptions by himself (logging, saving state for retry ex). And I have global exception handlers who also log all exceptions, can retry the operation and returns details to a client if it is possible. Like:
if (exception is ICustomException) return exception.Message;
else return "Something wrong";
Such exceptions like validation exceptions, pipeline action exceptions should not be logged and processed in global exceptions handlers.
Can I do something like
catch(Exception ex)
{
...
throw new CustomException() { IsHandled = true, Message = ex.Message}
}
or
exception.Data["handled"] = true;
to avoid double logging etc?
Is my architecture good enough in overall?
IsHandled
, useIsLogged
instead. Second, don't bother catching it in the intermediate places at all, and log it centrally.