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 94 views
1 answer 151 views
151 views asked Oct 8, 2022 by avibootz
2 answers 214 views
214 views asked Nov 22, 2020 by avibootz
2 answers 305 views
1 answer 222 views
...