Throwing exception exception caught by pointer
2 answers
Yes. Basically, you are throwing the object yourself in the first case. It looks like you threw the exception yourself on the line throw ex
. In the second case, you just let the original object go up in the call stack (and thus keep the original call stack), these are different. Usually you should use throw;
.
+7
a source to share
I think there is a performance difference. The second version will not create a temporary copy of the exception. The first one will create a copy, so seond is the way to go.
You can create a simple exception class and try it so that the copy constructor / constructor is printed to the console when they run. So you should see the difference.
-2
a source to share