C++异常处理

 1 #include<iostream.h>
 2 int Div(int x,int y);
 3 int main()
 4 {    try
 5     { cout<<"5/2="<<Div(5,2)<<endl;
 6       cout<<"8/0="<<Div(8,0)<<endl;
 7       cout<<"7/1="<<Div(7,1)<<endl;
 8     }
 9    catch(int)
10     { cout<<"except of deviding zero.\n"; }
11     cout<<"that is ok.\n";
12     while(1);
13     return 0;
14 }
15 int Div(int x,int y)
16 {    if(y==0) throw y;
17     return x/y;
18 }
19 
20 /*
21 程序运行结果如下:
22 5/2=2
23 except of deviding zero.
24 that is ok.
25 */
原文地址:https://www.cnblogs.com/hxsyl/p/2690474.html