Possible Duplicate:
What is the proper way to re-throw an exception in C#?
I want to understand why the “throw ex” usage hides the original stack trace? What was the fundamental philosophy behind the scene when designing c# compiler?
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.
This isn’t actually a C# question, but rather a CLI design question, and comes down to the different IL instructions,
throwandrethrow.Basically,
throw ex;(for anyex, even the original) is an ILthrow, where-asthrow;is an ILrethrow.If you are specifying a specific exception to throw, it follows that this exception is logically originating from here, now, this method. If that isn’t the case, then either:
rather than
throw ex;, or: wrap the exception in another exception, so you preserve the original exception and show where the new one came from:in which case the caller can obtain the original stack trace via
ex.InnerException.