How to rethrow an exception in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

void function()
{
	try {
		throw "throw from function()";              
	}
	catch (const char *) {          
		cout << "catch from function()" << endl;
		throw;                      
	}
}
int main()
{
	try {
		function();
	}
	catch (const char *) {
		cout << "catch from main()" << endl;
	}
	
	return 0;
}


/*
run:

catch from function()
catch from main()

*/

 



answered Jun 2, 2018 by avibootz

Related questions

2 answers 471 views
471 views asked Jun 19, 2018 by avibootz
1 answer 251 views
1 answer 187 views
2 answers 158 views
158 views asked Oct 21, 2022 by avibootz
...