Possible Duplicate:
catch exception by pointer in C++
I always catch exceptions by value. e.g
try{
...
}
catch(CustomException e){
...
}
But I came across some code that instead had catch(CustomException &e) instead. Is this a)fine b)wrong c)a grey area?
The standard practice for exceptions in C++ is …
Catching by value is problematic in the face of inheritance hierarchies. Suppose for your example that there is another type
MyExceptionwhich inherits fromCustomExceptionand overrides items like an error code. If aMyExceptiontype was thrown your catch block would cause it to be converted to aCustomExceptioninstance which would cause the error code to change.