C++编程中异常处理实例代码
- #include <iostream>
- #include <csetjmp>
- using namespace std;
- class Rainbow {
- public:
- Rainbow() {cout << "Rainbow()" << endl;}
- ~Rainbow() {cout << "~Rainbow()" << endl;}
- };
- void oz() {
- Rainbow rb;
- for(int i = 0; i < 3; i ) {
- cout << "theres no place like home" << endl;
- }
- throw 47;
- }
- int main()
- {
- try{
- cout << "tornado, witch, muchkins..." << endl;
- oz();
- }
- catch (int){
- cout << "Autie Em!"
- << " I had the strangest dream..."
- << endl;
- }
- return 0;
- }
- 输出:
- tornado, witch, muchkins...
- Rainbow()
- theres no place like home
- theres no place like home
- theres no place like home
- ~Rainbow()
- Autie Em! I had the strangest dream...
-
- Process returned 0 (0x0) execution time : 0.094 s
- Press any key to continue.
补充:软件开发 , C++ ,