From what I understand throw causes an exception.
It looks like it can be used to test your catch exception.
- What are the benefits/uses for it? Why would you want to purposely cause an exception?
-
Why use
throwincatch? Seems like it catches the exception just to cause an exception again.try { //blah } catch { throw; }
throw;rethrows the current exception. It’s used for when you want to catch an exception and do some handling of your own, but otherwise still want the exception to propagate more-or-less as if you never caught it.The difference (in languages that let you just say
throw;, like C#) is that when you rethrow an exception, the original stack trace remains mostly intact. (It includes the line where you rethrew the exception rather than the line where the exception occurred in the correspondingtryblock, but otherwise the whole stack trace is preserved.) If you saythrow the_exception_you_caught;, it’s usually treated as if you threw a brand new exception from right there — the existing stack trace gets obliterated and a new one starts from that point.