Solution:
#include<iostream>
using namespace std;
double x,y;
void read()
{
cout<<"\nEnter Two Double Type Values Except 0\n";
cin>>x>>y;
try
{
if(x==0||y==0)
{
throw 'x';
}
} catch(char)
{
cout<<"\n0 or Character Values Not Allowed";
}
}
void divide()
{
try
{
if(y==0)
{
throw 0;
}
else
{
cout<<"\nDivision Result is "<<x/y;
}
}
catch(int)
{
cout<<"\nDivide By Zero Exception Caught";
}
}
main()
{
read();
divide();
}
Output:
#include<iostream>
using namespace std;
double x,y;
void read()
{
cout<<"\nEnter Two Double Type Values Except 0\n";
cin>>x>>y;
try
{
if(x==0||y==0)
{
throw 'x';
}
} catch(char)
{
cout<<"\n0 or Character Values Not Allowed";
}
}
void divide()
{
try
{
if(y==0)
{
throw 0;
}
else
{
cout<<"\nDivision Result is "<<x/y;
}
}
catch(int)
{
cout<<"\nDivide By Zero Exception Caught";
}
}
main()
{
read();
divide();
}
Output: