异常处理的栈展开、析构函数和构造函数的异常,异常处理的层次
catch的搜索匹配 。。。
class wrong :public exception
{
public:
wrong(const int& i = 0,const string& str = ""):err_no(i),err_str(str){}
string what()
{
cout << "错误码: " << err_no << endl;
cout << "错误script: " << err_str<<endl;
return err_str;
}
private:
int err_no;
string err_str;
};
void throw_err()
{
throw wrong(1, "没鱼SB");
}
int main()
{
try {
try {
try {
throw_err();
}
catch (string&w) {
cout << "shabi" << endl;
}
}
catch (wrong& w) {
w.what();
}
}
catch (...) {
cout << "没鱼SB2" << endl;
}
system("pause");
return 0;
}