Program to illustrate the catching of all exceptions using single catch statement:
#include<iostream>
using namespace std;
void test()
{
int x;
cout<<"Enter Any Positive Value Except 0\n";
cin>>x;
if(x<0)
{
throw (float)x;
}
else if(x==0)
{
throw x;
}
cout<<"\nEntered Value is "<<x;
}
main()
{
try
{
test();
}
catch(...)
{
cout<<"\nException Caught";}
cout<<"\nEnd";
}
Output:
#include<iostream>
using namespace std;
void test()
{
int x;
cout<<"Enter Any Positive Value Except 0\n";
cin>>x;
if(x<0)
{
throw (float)x;
}
else if(x==0)
{
throw x;
}
cout<<"\nEntered Value is "<<x;
}
main()
{
try
{
test();
}
catch(...)
{
cout<<"\nException Caught";}
cout<<"\nEnd";
}
Output: