C++异常类使用
#include <string>
#include <iostream>
using namespace std;
class ObjectNULL
{
public:
ObjectNULL()
{
m_strMsg = "";
}
ObjectNULL(string msg)
{
this->m_strMsg = msg;
}
~ObjectNULL()
{
}
void Display()
{
cout << m_strMsg << endl;
}
string m_strMsg;
};
void main()
{
int nInput;
cin >> nInput;
try
{
if (nInput == 0)
{
ObjectNULL ex("输入的数据不能为零!");
throw ex;
}
}
catch (ObjectNULL e)
{
e.Display();
}
int wait;
cin >> wait;
}

浙公网安备 33010602011771号