this code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <string>
using namespace std;
class Class {
public:
string msg;
Class(string txt):msg(txt){cout<<"Object [" << msg << "] constructed" << endl; }
~Class(void) { cout << "Object [" << msg << "] destructed" << endl; }
void Hello(void) { cout << "Object [" << msg << "] says: hello" << endl; }
};
void DoCalculations(int i) {
if(i == 0)
throw Class("exception 1");
Class object("object");
if(i == 1)
throw Class("exception 2");
object.Hello();
if(i == 2)
throw Class("exception 3");
}
int main(void) {
for(int i = 0; i < 3; i++) {
try {
cout << "-------" << endl;
DoCalculations(i);
} catch (Class &exc) {
cout << "Caught!" << endl;
cout << exc.msg << endl;
}
}
return 0;
}
|
is supposed to output this :
-------
Object [exception 1] constructed
Caught!
exception 1
Object [exception 1] destructed
-------
Object [object] constructed
Object [exception 2] constructed
Object [object] destructed
Caught!
exception 2
Object [exception 2] destructed
-------
Object [object] constructed
Object [object] says: hello
Object [exception 3] constructed
Object [object] destructed
Caught!
exception 3
Object [exception 3] destructed
but when i run it using my visual studio express 2012 (with update 4) it displays this output :
-------
Object [exception 1] constructed
Object [exception 1] destructed
Caught!
exception 1
Object [exception 1] destructed
-------
Object [object] constructed
Object [exception 2] constructed
Object [exception 2] destructed
Object [object] destructed
Caught!
exception 2
Object [exception 2] destructed
-------
Object [object] constructed
Object [object] says: hello
Object [exception 3] constructed
Object [exception 3] destructed
Object [object] destructed
Caught!
exception 3
Object [exception 3] destructed
it displays one more "Object [exception n] destructed" statement after each "Object [exception n] constructed" statement, why does it act like this ?