Jul 13, 2001 #1 jyotsna24 Programmer Jun 24, 2001 15 IN Hi, Hoe can we use 'try' 'catch' block in cpp using classes?Pls give me an example also. Thanx in advance.
Hi, Hoe can we use 'try' 'catch' block in cpp using classes?Pls give me an example also. Thanx in advance.
Jul 13, 2001 #2 Cagliostro Programmer Sep 13, 2000 4,226 GB #include<iostream> using namespace std; void xxx(int x) { char* xxx="no result"; switch(x) { case o: throw "wrong vallue, x can't be 0"; case 1: throw xxx; case 3:case 4:case 5: cout<<"accepted value "<<x<<endl; break; default: if(x<100&&x>10) { throw x; }else { throw; } } } int main() { cout<<"enter a value>" cin>>c; try { xxx(c); }catch(char* err) { cout<<"error:"<<err<<endl; }catch(int ierr) { cout<<"undescribed error with code:"<<ierr<<endl; }catch(...) { cout<<"unknown error"<<endl; } return 0; } John Fill ivfmd@mail.md Upvote 0 Downvote
#include<iostream> using namespace std; void xxx(int x) { char* xxx="no result"; switch(x) { case o: throw "wrong vallue, x can't be 0"; case 1: throw xxx; case 3:case 4:case 5: cout<<"accepted value "<<x<<endl; break; default: if(x<100&&x>10) { throw x; }else { throw; } } } int main() { cout<<"enter a value>" cin>>c; try { xxx(c); }catch(char* err) { cout<<"error:"<<err<<endl; }catch(int ierr) { cout<<"undescribed error with code:"<<ierr<<endl; }catch(...) { cout<<"unknown error"<<endl; } return 0; } John Fill ivfmd@mail.md