??????????????????μ??????????????????C++????????
??????VC++?У??ж?????????????????????
????No exception handling (????????)
????C++ only ??C++???????????
????C++ ??SEH ??C++?????windows ????????????
???????????????????????????????????????????????????C++???????????????????????????????
// simple class
class MyAppObject
{
public:
MyAppObject(int id) : _myID(id) {}
~MyAppObject();
int _myID;
void DoSomething(int throwWhat) ;
};
// can throw 2 different exception
void MyAppObject::DoSomething(int throwWhat)
{
printf("MyAppObject::DoSomething called for '%d' "?? _myID);
switch (throwWhat)
{
case 0:
break;
case 1:
this->_myID /= 0;             // exception 1
break;
case 2:
throw SimpleString("error!"); // exception 2
break;
}
}
// Test exception for the above class
void TestMyAppObject()
{
printf("before try”);
try                                                          // line1
{
printf("in try”);
MyAppObject so = 1;                          // line2
SimpleString ss("test ex point one");    // line3
so.DoSomething(1);                           // line4
printf("so::ID called for '%d' "?? so._myID);
MyAppObject so2 = 2;                       // line5
printf("so2::ID called for '%d' "?? so2._myID);
so2.DoSomething(0);                        // line6
}
catch(const SimpleString &e)                   // line7
{
//printf("something happened: %s "?? e);
}
catch(...)                                    //line8
{
//printf("something happened: %s "?? "SEH");
}
}
????????????????????“no exception”??????????line1??line7??line8??????????size???
????Exe
????Obj
????32??256 bytes
????20??931 bytes
??????????line4???????“??0”??????????????????????????????????????????????????????????????????????????????????????????