46.一个例子了解C++中异常处理
生活随笔
收集整理的這篇文章主要介紹了
46.一个例子了解C++中异常处理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
異常處理的棧展開、析構函數和構造函數的異常,異常處理的層次
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; }?
?
總結
以上是生活随笔為你收集整理的46.一个例子了解C++中异常处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UBUNTU下gedit编辑器出现中文乱
- 下一篇: SIP协议状态码:480Temporar