您的位置:首页 > 编程语言 > C语言/C++

C++ 标准库中的异常

2016-10-28 10:48 176 查看
#include<iostream>

#include <exception>

#include <stdexcept>

using namespace std;

class CException:public std::exception

{
public:
std::string s;
CException(std::string ss):s(ss)
{

}
~CException()throw()
{

}
const char* what() const throw()
{
return s.c_str();
}

};

int main()

{
try
{
throw CException("11");
cout << "end try" << endl;
}
catch(std::exception& e)
{
cout << "CException: " << e.what() << endl;
}
cout << "end" << endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: