Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to use try catch inside a function in C++

1 Answer

0 votes
#include <iostream>

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

void function(int n)
{
	try {
		if (n)
			throw n;
	}
	catch (int __n) {
		cout << "catch n = " << __n << endl;
	}
}

int main()
{
	function(99);
	function(0);
	function(13);

	return 0;
}




/*
run:

catch n = 99
catch n = 13

*/

 



answered Jun 2, 2018 by avibootz

Related questions

2 answers 182 views
1 answer 117 views
117 views asked Oct 8, 2022 by avibootz
1 answer 148 views
148 views asked Jul 11, 2022 by avibootz
1 answer 205 views
205 views asked Jun 4, 2021 by avibootz
1 answer 187 views
1 answer 156 views
156 views asked Apr 3, 2021 by avibootz
...