Answer to Question #328771 in C++ for Tanuj Verma

Question #328771

WAP in c++ containing a possible exception. Use a try block to throw it and a catch block to handle it promptly.


1
Expert's answer
2022-04-14T11:24:07-0400
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS