Logging cannot be considered in isolation of the exception handling strategies
As a rule of thumb, my default position on exception handling looks like this:
- If you can handle an exception, recover from it and continue
- If you can’t handle an exception, but you can translate it, then do so and continue.
- If you can’t handle an exception and you won’t translate it, then propagate it to someone who can.
If you’re going to handle an exception, you may choose to log the details.
If you translate an exception and still propogate that, log the exception only if you aren’t going to propogate it
If you can’t handle an exception and you won’t translate it, don’t bother logging it. Ensure that someone higher up is going to apply the first two rules.
Think of what would information would help you at 3am in the morning