#include<iostream>
using namespace std;
#include<stdexcept>
#include<string>
class MyException:public exception
{
public:
MyException(const char*p)
{
this->m_p = p;
}
virtual const char*what()
{
cout << "MyException 类型" << m_p << endl;
return m_p;
}
private:
const char*m_p;
};
void testMyException()
{
throw MyException("函数异常");
}
int main(void)
{
try
{
testMyException();
}
catch (MyException &e)
{
e.what();
}
catch (...)
{
cout << "其他未知类型的异常" << endl;
}
system("pause");
return 0;
}
/*
* MyException 类型函数异常
请按任意键继续. . .
*/
010从标准异常类派生自己的异常类MyException
猜你喜欢
转载自blog.csdn.net/baixiaolong1993/article/details/89502478
今日推荐
周排行