I want this code to call generic catch block whenever any special character(eg. !,@,#,$,%,&,*, etc) is enetered in numerator or denominator. So what code should I add to this.
Any help would be appreciated. Thanks.
#include <iostream>
using namespace std;
int main()
{
try // generic catch block
{
int num, den;
double division;
try
{
cout << "\n enter numerator(+ve no. only): ";
cin >> num ;
if (num<0) throw 3.2 ;
}
catch(double m)
{
cout << "\n ERROR: numerator should be positive ";
num = -num ;
cout << "\n\n So your new numerator is: " << num;
}
try
{
cout << "\n\n enter denominator: ";
cin >> den ;
if (den==0) throw 1;
}
catch(int n)
{
cout << "\n ERROR: You can't divide a no. by zero, enter another no: ";
cin >> den;
}
division = double(num)/den;
cout << "\n result is: " << division << "\n\n ";
}
catch(...) // Generic catch block
{
cout << "/n/n Unexpected Error: Contact your software provider";
}
system("PAUSE");
return EXIT_SUCCESS;
}