How can I handle the following exception without using if/else ( only using try/catch):-
string S;
cin >> S;
stringstream ss(S);
int n;
try {
ss>>n;
if(ss.fail()) throw (exception())
else cout<<n;
}
catch (const exception& e) { cout << "Bad String"<<endl;}
Aucun commentaire:
Enregistrer un commentaire