65,186
社区成员




#include <iostream>
using namespace std;
class UserException
{
public:
/// Copy constructor.
UserException ()
{}
/// Destructor.
virtual ~UserException (void){}
};
class UserException2
{
public:
/// Copy constructor.
UserException2 ()
{}
virtual void func(){}
/// Destructor.
virtual ~UserException2 (void){}
};
class test
{
public:
void call ()throw(UserException2)
{
cout << "call" << endl;
//抛出的异常类型和函数声明的异常类型不同。程序在这里崩溃
throw UserException();
//如果抛出下面这个异常,自然是没问题的。
//throw UserException2();
}
};
int main(int argc, char *argv[])
{
UserException bs;
test mm;
try
{
mm.call();
}
catch(UserException & ex)
{
cout << "UserException1" << endl ;
}
catch(UserException2 & ex)
{
cout << "UserException2" << endl ;
}
catch (...)
{
}
cout << "oo" << endl ;
return 0;
}