|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
#include<string.h>
#include<stdexcept>
using namespace std;
class MyException
{
private:
char msg[100];
public:
MyException()
{
cout<<"Constructor2"<<endl;
}
MyException(const char *c)
{
cout<<"Constructor"<<endl;
strcpy(msg,c);
}
void what()
{
cout<<msg<<endl;
}
~MyException()
{
cout<<"Disconstructor"<<endl;
}
};
void Div(int a,int b)
{
if(b==0)
{
throw (MyException("b==0"));
// cout<<"div"<<endl;
}
}
int main()
{
int a,b;
cin>>a>>b;
try
{
Div(a,b);
}
catch(MyException e)
{
e.what();
}
return 0;
}
请问throw (MyException("b==0"));中,为什么MyException后可以直接赋值?
|
|