www.gusucode.com > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序 > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序/code/C++例题程序/第6章/s6_19/smain6_191.cpp
//Download by http://www.NewXing.com //文件名:smain6_19.cpp //异常基本结构。 #include <iostream> using namespace std; void trigger(int iNum) throw(int, char, double) { switch(iNum) { case 0: throw 0; case 1: throw 'E'; case 2: throw 3.14; default:throw "I'm a exception!"; } } void CallTrigger(int iNum) { try { trigger(iNum); } catch(int i) { cout << "Catch “integer = " << i << " exception” in CallTrigger()!" << endl; } catch(char ch) { cout << "Catch “charactor = " << ch << " exception” in CallTrigger()!" << endl; } catch(double d) { cout << "Catch “double float = " << d << " exception” in CallTrigger()!" << endl; } return; } int main() { try { for (int i=0; i<4; i++) { CallTrigger(i); } } catch(char *msg) { cout << "Catch “msg =" << msg << " exception” in main()!" << endl; } return 0; }