This question was sparked by a discussion around this article, where I did not receive any good answers.
Why should logging your exception and then rethrowing it (preserving the original stack trace of course) be a bad idea if you can't handle it otherwise?
I guess the simplest reason is that you'd typically have a single top-level handler doing this for you, so there's no need to pollute the code with this exception handling.
The cross-cutting concerns argument is basically that it is a waste of time handling errors that don't concern you. Far better to let the error bubble up the call stack until an appropriate handler can be found.
In my opinion, the only time you should catch an exception is when you can do something useful with the results. Catching simply to log is not useful, because you could centralize that work further up.
IMO log and throw is a clear violation of the Principle of Least Surprise.
If the exception is handled properly further up the call stack, it might not be worth an error log entry at all. And then it is confusing to find an error log entry.
Log-and-throw is a good pattern iff the entity catching and rethrowing the exception has reason to believe that it contains information which will not get logged further up the call stack--at least not in the most-desired fashion. A couple of reasons this may occur:
I assume the answer is largely because why are you catching it if you can't handle it? Why not let whomever can handle it (or whomever is left with no choice but to handle it) log it, if they feel that it is log-worthy?
If you catch it and log it and rethrow it, then there's no way for the upstream code to know that you've already logged the exception, and so the same exception might get logged twice. Or worse, if all the upstream code follows this same pattern, the exception might be logged an arbitrary number of times, once for each level in the code that decides to catch it, log it, and then throw it again.
Also some might argue that since throwing and catching exceptions are relatively costly operations, all this catching and rethrowing isn't helping your runtime performance. Nor is it helping your code in terms of conciseness or maintainability.