-
how to handle exceptions
hi...i m learning the concepts of exception handling and trying to run my first program using try- catch block.
the problem is the compiler is not able to identify try and catch keywords.
is there a problem in the compiler or do i have to include any special header file for it.??
plz guide me...the code is as follows:
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b;
cin>>a>>b;
int x=a-b;
try
{
if(x!=0) cout<<“Result (a/x)”<<a/x<<“\n”;
else throw(x);
}
catch (int i)
{
cout<< “Exception caught”<<i<<“\n”;
}
cout<<“End”;
getch();
}
-
can nobody help me out..????
plz do...im stuck.... :confused:
-
you only waited 10 minutes before bumping your thread! gonna have to have more patience than that :)
note, you are using C-style header files.. get rid of the '.h'. and change 'void main' to 'int main'.
edit: it looks your logic actually works, however your program doesnt compile under a C++ compiler. after you get it to compile, your exception handling will work.