w***@gmail.com
2008-12-04 02:20:47 UTC
For the purpose of practicing C++ exception handling, I invented a
trivial program as follows:
class SE_Exception {
private:
SE_Exception() {}
unsigned int nSE;
public:
SE_Exception( SE_Exception& e) : nSE(e.nSE)
{
puts("SE_Exception Copy Constructor");
}
SE_Exception(unsigned int n) : nSE(n)
{
puts("SE_Exception Constructor");
}
SE_Exception& operator=(SE_Exception& e)
{
nSE = e.nSE;
puts("SE_Exception assignment operator");
return *this;
}
bool operator==(SE_Exception& e)
{
puts("SE_Exception equality comparison operator");
return nSE==e.nSE;
}
~SE_Exception()
{
puts("SE_Exception Destructor");
}
};
int main() {
_set_se_translator( trans_func );
try {
SE_Exception* e = new SE_Exception(94);
throw e;
}
catch( SE_Exception e ) {
printf_s( "Caught a __try exception with SE_Exception.\n" );
}
}
I run the program and find that there are two exceptions. The first
one is an unhandled exception, which meets my expectancy. The second
one, however, surprisingly, is an exception with respect to kind of
buffer-overflow. Could anyone explain the details? Please!
trivial program as follows:
class SE_Exception {
private:
SE_Exception() {}
unsigned int nSE;
public:
SE_Exception( SE_Exception& e) : nSE(e.nSE)
{
puts("SE_Exception Copy Constructor");
}
SE_Exception(unsigned int n) : nSE(n)
{
puts("SE_Exception Constructor");
}
SE_Exception& operator=(SE_Exception& e)
{
nSE = e.nSE;
puts("SE_Exception assignment operator");
return *this;
}
bool operator==(SE_Exception& e)
{
puts("SE_Exception equality comparison operator");
return nSE==e.nSE;
}
~SE_Exception()
{
puts("SE_Exception Destructor");
}
};
int main() {
_set_se_translator( trans_func );
try {
SE_Exception* e = new SE_Exception(94);
throw e;
}
catch( SE_Exception e ) {
printf_s( "Caught a __try exception with SE_Exception.\n" );
}
}
I run the program and find that there are two exceptions. The first
one is an unhandled exception, which meets my expectancy. The second
one, however, surprisingly, is an exception with respect to kind of
buffer-overflow. Could anyone explain the details? Please!