c++中 throw try catch的浅显应用

来源:互联网 发布:程序员专用壁纸高清 编辑:程序博客网 时间:2024/05/12 00:48
#include <iostream>#include <stdlib.h>using namespace std;void func(int a,int b){if(b==0)throw b;cout<<a/b<<endl;}int main(){int a,b;while (cin>>a>>b){try{           func(a,b);}catch(...){cout<<"是否需要重新输入:y或者n"<<endl;char str;cin>>str;if(!cin||str=='n')break;}}system("pause");return 0;}

0 0
原创粉丝点击