正在加载图片...
C++语言程序设计 湖南科技大学 例12-1处理除零异常 #includeiostream. h> int Div(int x, int y) int maino itry cout<"5/2="<<Div(5,2)<<end1; cout<< 8/0="<<Div(8, 0)<end1 cout<< 7/1="<<Div(7, 1)<<endl catch(int i cout<<"except of deviding zero. \ n cout<< that is ok int Div(int x, int y) if(y==0)throw y 程序运行结果如下: return x/y 5/2=2 except of deviding zero. that is ok 6C++语言程序设计 湖南科技大学 6 例12-1处理除零异常 #include<iostream.h> int Div(int x,int y); int main() { try { cout<<"5/2="<<Div(5,2)<<endl; cout<<"8/0="<<Div(8,0)<<endl; cout<<"7/1="<<Div(7,1)<<endl; } catch(int) { cout<<"except of deviding zero.\n"; } cout<<"that is ok.\n"; } int Div(int x,int y) { if(y==0) throw y; return x/y; } 程序运行结果如下: 5/2=2 except of deviding zero. that is ok
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有