Is there any valid reason why a catch
block on a lower layer would throw back an exception caused by a higher, unknown layer using the following syntax:
throw ex;
… rather than:
throw;
… ?
In the first case, not only the catch
block doesn’t deal with the exception, but it also reset its StackTrace
property, making it more difficult to understand what caused it.
Why would anyone want a catch
block in a lower layer to behave like this?
2
First off, having a catch
block which only rethrows the exception is usually useless. But, the only real world scenario i can think of which makes sense to use throw ex
instead of throw
is if you’re developing some sort of third party library which you by all means dont want anyone in the outter scope who’s using your code to see the full stacktrace. Im not saying this is a good thing, but it might happen.
3