练习5.25

关于异常处理

#include <iostream>
//#include <string>
#include <stdexcept>
using namespace std;
int main()
{
    int a,b;
    string reply;
    while(cin>>a>>b){
        try{
            if(b==0)
            throw range_error("don't put 0");
            cout<<a/b<<endl;}
        catch(range_error err){
        if(b==0){
            cout<<err.what()<<endl;
            cout<<"do you want to continue?"<<endl;
            cin>>reply;
            if(reply[0]=='n')
                break;
        }
    }
}
    return 0;
}


posted @ 2014-12-25 17:15  Song_4  阅读(111)  评论(0)    收藏  举报