What’s the difference between using
catch(Exception ex)
{
...
throw ex;
}
and using
catch // might include (Exception)
{
...
throw;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
throw exre-throws the exception object from that point. This is generally bad, since it destroys the useful call stack information which lead up to the original problem.throwreleases the original caught exception, from the point it was actually thrown. It retains the call stack information up to that point, instead of to the point you caught.catch(Exception)andcatchare essentially the same thing, except obviously the first gives you the exception object to do something with, and the second does not. But both will catch all exceptions. They are distinct fromcatch(SomeKindOfException), which will only catch exceptions of that specific type (or more specific types derived from that type). This is best for situations like: