What does "throw;" by itself do?

.net, c#, exception

Solution

By itself, the `throw` keyword simply re-raises the exception caught by the `catch` statement above. This is handy if you want to do some rudimentary exception handling (perhaps a compensating action like rolling back a transaction) and then rethrow the exception to the calling method.

This method has one significant advantage over catching the exception in a variable and throwing that instance: It preserves the original call stack. If you catch (Exception ex) and then throw ex, your call stack will only start at that throw statement and you lose the method/line of the original error.

Problem

Possible Duplicate: difference between throw and throw new Exception() What would be the point of just having ``` catch (Exception) { throw; } ``` What does this do?

Original source

Related problems