When I write my try/catch
blocks, I always throw objects by value and exit the link. I also apply the rule that the most derived classes should be first.
Today I tried to catch BY VALUE, breaking this basic rule. The code below runs without any problems and prints "A4"
.
Question: What type of CCA
argument is passed to the exception handler that runs? The original object that was reset, the CCB
is passed by value to the CCA
object: this is an example of a memory clipping problem or some distortion, i.e. CCA
n't trust the CCA
?
Hello
AFG
class CCA{ int m_value; public: CCA( int value ) : m_value( value ){} }; class CCB : public CCA{ public: CCB( int value ): CCA( value ){} }; main(){ try{ throw CCB(4); }catch( CCA a ){ std::cout << " A:" << a.value() << std::endl;
source share