程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> C++編程中異常處理實例代碼

C++編程中異常處理實例代碼

編輯:C++入門知識

  1. #include <iostream>
  2. #include <csetjmp>
  3. using namespace std;
  4. class Rainbow {
  5.     public:
  6.         Rainbow() {cout << "Rainbow()" << endl;}
  7.         ~Rainbow() {cout << "~Rainbow()" << endl;}
  8. };
  9. void oz() {
  10.     Rainbow rb;
  11.     for(int i = 0; i < 3; i ) {
  12.         cout << "theres no place like home" << endl;
  13.     }
  14.     throw 47;
  15. }
  16. int main()
  17. {
  18.     try{
  19.         cout << "tornado, witch, muchkins..." << endl;
  20.         oz();
  21.     }
  22.     catch (int){
  23.         cout << "Autie Em!"
  24.              << " I had the strangest dream..."
  25.              << endl;
  26.     }
  27.     return 0;
  28. }
  29. 輸出:
  30. tornado, witch, muchkins...
  31. Rainbow()
  32. theres no place like home
  33. theres no place like home
  34. theres no place like home
  35. ~Rainbow()
  36. Autie Em! I had the strangest dream...
  37.  
  38. Process returned 0 (0x0)   execution time : 0.094 s
  39. Press any key to continue.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved