My program is as follows: (on linux)
#include<iostream>
using namespace std;
int divn(int n, int d)
{
if(d == 0)
throw "Division by ZERO not possible ";
return n/d;
}
main()
{
int numer, denom;
cout << "Enter the numerator and denominator : ";
cin >> numer >> denom;
try
{
cout << numer << " / " << denom << " = " << divn(numer,denom) << endl;
}
catch(char *msg)
{
cout << msg;
}
cout << "\nEnd of main() \n ";
}
/ * it should throw an exception and provide this error message when we put the denominator as 0. The output I get when I enter the denotation, since 0 looks like this:
administrator @ubuntu: ~ / FYMCA / CPP_class $ g ++ prog110.cpp admin @ubuntu: ~ / FYMCA / CPP_class $. / a.out Enter the numerator and denominator: 12 0 termination of the call after calling the instance 'char const *' Aborted (core dumped )
How to solve the problem?
source
share