46.一个例子了解C++中异常处理

xiaoxiao2025-11-02  3

异常处理的栈展开、析构函数和构造函数的异常,异常处理的层次

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; }

 

 

转载请注明原文地址: https://www.6miu.com/read-5038946.html

最新回复(0)