exp 18
unknown
plain_text
9 months ago
712 B
13
Indexable
#include<iostream>
#include<stdexcept>
using namespace std;
class Exception :public runtime_error {
public:
Exception()
:runtime_error("math error:attempted to divide by zero\n")
{
}
};
float Division (float num,float den)
{
if(den == 0)
throw Exception();
return(num/den);
}
int main()
{
float numerator,denominator ,result;
numerator =12.5;
denominator=0;
try{result= Division (numerator,denominator);
cout<<"The quotient is"<<result<<endl;
}
catch (Exception & e)
{
cout<<"Exception occured"<<endl
<<e.what();
}}
Editor is loading...
Leave a Comment