Below is the given code. What I want is that if a condition for throw is matched (here it is division by zero), the program should directly terminate after giving the kind of exception I want (here it is "denominator zero!"). Usually, this can be done just by writing throw statement (without writing catch statement) but the way it ends is disturbing as the IDE(eclipse in my case) shows a pop-up window telling the "program_name.exe stopped working" in window PC. Is there a better way to end the program after throwing the exception which should appear in the output window itself without these unusual looking pop-ups? (may be a custom exception format would be better)
#include <iostream>
#include <string>
using namespace std;
double div(double num, double denom)
{
double result = 0.0;
try
{
if(denom == 0)
throw "denominator zero!\n";
result = num/denom;
}
catch(const char* e)
{
cout<<e<<endl;
}
return result;
}
int main()
{
double a = 5.0;
double b = 0.0;
cout<<div(a,b);
return 0;
}