Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exception handling

Status
Not open for further replies.

jyotsna24

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


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top