In C++, what is the difference between the following examples?
Re-throw pointer:
catch (CException* ex)
{
throw ex;
}
Simple re-throw:
catch (CException* ex)
{
throw;
}
When the re-throw is caught, will the stack trace be different?
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.
Yes. Basically, you are throwing the object yourself in the first case. It looks like you generated the exception yourself in the
throw exline. In the second case, you are just letting the original object go up in the call stack (and thus preserving the original call stack), those are different. Usually, you should be usingthrow;.