|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
using namespace std;
void myfunc();
class expt
{
public:
expt()
{}
~expt()
{}
const char *showreason() const
{
return "expt异常";
}
};
class Demo
{
public:
Demo()
{
cout<<"Demo::构造"<<endl;
}
~Demo()
{
cout<<"Demo::析构"<<endl;
}
};
void myfunc()
{
Demo D;
cout<<"在myfunc()中抛掷expt类异常"<<endl;
throw expt();
}
int main()
{
cout<<"在main()中"<<endl;
try
{
cout<<"在try中"<<endl;
//myfunc();
throw "i love you";
}
catch(expt e)
{
cout<<e.showreason()<<endl;
}
catch( char *str) //如果改为 catch( char *str)则可以
{
cout<<"捕获到其它的异常"<<endl;
cout<<str<<endl;
}
cout<<"回到main()函数"<<endl;
return 0;
}
请问:catch( char *str) //如果改为 catch( char *str)则可以,为什么?
|
|