T
Thomas Lenz
Could someone please consider my first prog. with a C++ Exception? Here it
is:
#include <iostream>
using namespace std;
class MyException
{ public:
MyException();
~MyException();
private:
};
MyException::MyException()
{ cout << "MyException Construktor" << endl;
}
MyException::~MyException()
{ cout << "MyException Destruktor" << endl;
}
int main()
{
try
{ throw MyException();
cout << endl;
}
catch (MyException)
{ cout << "Exception happened." << endl;
}
cout << "Ende" << endl;
}
It compiles well, but produces the following output:
MyException Construktor
Exception happened.
MyException Destruktor
MyException Destruktor
Ende
Could someone please explain why the hell the Destructor is invoked twice?
Thanks in advance, Thomas
is:
#include <iostream>
using namespace std;
class MyException
{ public:
MyException();
~MyException();
private:
};
MyException::MyException()
{ cout << "MyException Construktor" << endl;
}
MyException::~MyException()
{ cout << "MyException Destruktor" << endl;
}
int main()
{
try
{ throw MyException();
cout << endl;
}
catch (MyException)
{ cout << "Exception happened." << endl;
}
cout << "Ende" << endl;
}
It compiles well, but produces the following output:
MyException Construktor
Exception happened.
MyException Destruktor
MyException Destruktor
Ende
Could someone please explain why the hell the Destructor is invoked twice?
Thanks in advance, Thomas