P
PasalicZaharije
Hallo,
few days ago I see ctor like this:
Ctor() try : v1(0) {
// some code
}
catch(...) {
// some code
}
This is something realy shocking for me. So I write something like:
class Kljasa {
int *bvarijabla;
public:
// first ctor
Kljasa(int cvarijabla) try {
bvarijabla = new int[cvarijabla];
}
catch(...) {
cout << "CTOR DOWN" << endl;
bvarijabla = NULL;
}
//second like first with try block inside
Kljasa(int cvarijabla, int dummy) {
try {
bvarijabla = new int[cvarijabla];
}
catch(...) {
cout << "CTOR DOWN" << endl;
bvarijabla = NULL;
}
}
};
If I write:
Kljasa k(-10, 1); // second ctor
everithing is OK - exception is catched and programm continues to execute
(I know that this ctor-catching is not good solution but suppose that it's
ok).
Now, when I try to call first ctor my program
crashs with "abnormal program termination" but catch block displayed "CTOR
DOWN". It sems like
catch block rethrow exception again?!
My qusetion is: what first ctor realy do if exception is throwed?
Note, that I tested this only with MinGW 3.4.2.
Thanks,
Zaharije Pasalic
few days ago I see ctor like this:
Ctor() try : v1(0) {
// some code
}
catch(...) {
// some code
}
This is something realy shocking for me. So I write something like:
class Kljasa {
int *bvarijabla;
public:
// first ctor
Kljasa(int cvarijabla) try {
bvarijabla = new int[cvarijabla];
}
catch(...) {
cout << "CTOR DOWN" << endl;
bvarijabla = NULL;
}
//second like first with try block inside
Kljasa(int cvarijabla, int dummy) {
try {
bvarijabla = new int[cvarijabla];
}
catch(...) {
cout << "CTOR DOWN" << endl;
bvarijabla = NULL;
}
}
};
If I write:
Kljasa k(-10, 1); // second ctor
everithing is OK - exception is catched and programm continues to execute
(I know that this ctor-catching is not good solution but suppose that it's
ok).
Now, when I try to call first ctor my program
crashs with "abnormal program termination" but catch block displayed "CTOR
DOWN". It sems like
catch block rethrow exception again?!
My qusetion is: what first ctor realy do if exception is throwed?
Note, that I tested this only with MinGW 3.4.2.
Thanks,
Zaharije Pasalic