Answer to Question #273230 in C++ for Ajay

Question #273230

Write a program to try-catch blocks can be nested. Also ,an exception can be re-thrown using thrown

1
Expert's answer
2021-11-30T00:37:02-0500
#include <iostream>
using namespace std;


int main()
{
int x = -1;


// Some code
cout << "Before try \n";
try {
	cout << "Inside try \n";
	if (x < 0)
	{
		throw x;
		cout << "After throw (Never executed) \n";
	}
}
catch (int x ) {
	cout << "Exception Caught \n";
}


cout << "After catch (Will be executed) \n";
return 0;
}

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