WAP in c++ containing a possible exception. Use a try block to throw it and a catch block to handle it promptly.
#include<iostream>
using namespace std;
int main()
{
double a, b;
do
{
cout << "\nPlease, enter a number a (0 - exit program): ";
cin >> a;
if (a == 0)break;
cout << "Please, enter a number b: ";
try
{
cin >> b;
if (b == 0)
throw "Division by zero!";
cout << "Result of division is " << a / b;
}
catch (const char* exception)
{
cerr << "Error: " << exception << endl;
}
} while (true);
}
Comments
Leave a comment