I am trying to use the try catch for any kind of exception by using catch(...) but it is not catching the exception. Is there any method through which i can catch any exception which occurs in a particular function or logic.
int main()
{
try
{
int a=4,b=0;
int c;
c=a/b;
cout<<"c="<<c;
throw;
}
catch(...)
{
cout<<"\ndivision by zero";
}
_getch();
}
AFAIK throw; simply forwards the current exception. Since you have no exception, I don't really know what it would do. Try something like throw std::exception();
means i need to throw an exception if it not in there. Actually i was looking for a way so that i need not to throw any exception but then also the catch block catches it as in java it does.