How to use automatically called terminate handler function if no catch handler found for throw in C++

1 Answer

0 votes
#include <iostream>
#include <exception>

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

void terminate() {
	std::cerr << "set_terminate called" << endl;
	abort();  
}

int main() 
{
	std::set_terminate(terminate);
	throw 0;  // unhandled exception: call set_terminate

	return 0;
}


/*
run:

set_terminate called

*/

 



answered Jun 4, 2018 by avibootz

Related questions

1 answer 79 views
1 answer 134 views
134 views asked Oct 8, 2022 by avibootz
2 answers 192 views
192 views asked Nov 22, 2020 by avibootz
2 answers 285 views
1 answer 210 views
...