another reason this is poor practice is that catching and re-throwing an exception in the same fashion as the InvalidOperationException is adding bumf into the stack trace
–
jcvandanMay 11 '11 at 12:46

6 Answers
6

The real danger of this (other than being completely useless...) is that it modifies the call stack. Others have briefly mentioned it in comments, but it deserves to be called out specifically.

When you have throw ex;, the previous call stack is blown away and replaced with the call stack at the point where throw ex; is called. You almost never want to do this. I will often catch an exception, log it, then rethrow the exception. When doing that, you want to just use throw;. This will preserve the original stack trace.

While I agree that the code makes little sense, it couldn't be rewritten like that as throw e; actually modifies the stack trace captured in the instance (probably not the intention but still ...)
–
Brian RasmussenMay 11 '11 at 12:44

Makes no sense whatsoever to me, but not for the reason you might think.

Catching an exception is not the same thing as handling it. This try/catch block does no handling at all. I think a better, more honest, less verbose solution would have been to remove the try/catch and let the exceptions bubble up to where they can/should be dealt with.

It is possible that they wanted to implement different handling for InvalidOperationException and other types of exceptions, so they wrote this code as a stub. But then this idea was abandoned so you see this code artifact.