exception - STL C++

set_terminate()

Declaration

terminate_handler set_terminate(terminate_handler qNewHandler) throw();

Description

This is the function set_terminate() in the exception header. This function sets the handler that is to be called when the program terminates. The function returns the previous termination handler.

Header Include

#include <exception>

Example

#include <iostream>
#include <exception>

void NewTerminate() {
	std::cout << "The end." << std::endl;
	abort();
}

int main() {
	// Set a new terminate handler and get the old one back
	terminate_handler qOldTerminate = set_terminate(NewTerminate);

	// Throw anything to call the terminate function
	throw "XoaX.net";

	return 0;
}

Output

set_terminate() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.