exception - STL C++

set_unexpected()

Declaration

unexpected_handler set_unexpected(unexpected_handler qNewHandler) throw();

Description

This is the function set_unexpected() in the exception header. This function sets the handler that is to be called when an unexpected exception is thrown and not caught. The function returns the previous unexpected handler.

Header Include

#include <exception>

Example

#include <iostream>
#include <exception>

void NewUnexpected() {
	std::cout << "Unexpected exception handler!" << std::endl;
	terminate();
}

int main() {
	// Set a new unexpected handler and get the old one back
	unexpected_handler qOldUnexpected = set_unexpected(NewUnexpected);

	// Call the unexpected function directly
	unexpected();

	return 0;
}

Output

set_unexpected() Output
 

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