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;


}

posted @ 2013-06-26 18:41  Predator  阅读(127)  评论(0编辑  收藏  举报