异常传递过程异常累的切割问题,
// Test20110115.cpp : 定义控制台应用程序的入口点。
// 异常传递机制 案例调研
#include "stdafx.h"
#include<iostream>
#include<string>
#include<Windows.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
class myException
{
public:
myException():excName("default baseExction")
{
cout<<"default myException construct"<<endl;
}
myException(string name)
{
excName = name;
cout<<"myException construct"<<endl;
}
virtual string getName()
{
return excName;
}
private: string excName;
};
class deriverExcetion:public myException
{
public:
deriverExcetion():dexcName("defualt deriverExcetion")
{
cout<<"default deriverExcetion construct"<<endl;
}
deriverExcetion(string name)
{
dexcName =name;
cout<<"deriverExcetion construct"<<endl;
}
string getName()
{
return dexcName;
}
private: string dexcName;
};
int main(int argc, _TCHAR* argv[])
{
cout<<"hello word"<<endl;
string excMessage;
deriverExcetion mydexc("deriverExcetion constructed");
///cout<<" mydexc.getName() 地址:"<<(int)(&mydexc.getName())<<endl;
try
{
throw &mydexc;
}
catch(myException *exc)
{
excMessage =exc->getName();
cout<<"excMessage: "<<excMessage<<endl;
//throw *exc;
}
try
{
throw mydexc;
}
catch(deriverExcetion exc)
{
excMessage =((myException)exc).getName();
cout<<"excMessage: "<<excMessage<<endl;
//throw ((myException)exc);
}
//catch(myException exc)
//{
// excMessage =exc.getName();
// cout<<"excMessage: "<<excMessage<<endl;
// //throw *exc;
//}
cin.get();
return 0;
}