The set_unexpected(), unexpected() and terminate() C++ exception program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info:
To do: Setting the set_unexpected() and then expect unexpected() C++ exception
To show: The set_unexpected(), unexpected() and terminate() C++ exception code sample
// set_unexpected()
#include <exception>
#include <iostream>
using namespace std;
void myfunction()
{
cout<<"Testing myfunction()."<<endl;
// terminate() handler
terminate();
}
int main(void)
{
unexpected_handler oldHandler = set_unexpected(myfunction);
// unexpected() function call
unexpected();
}
Output example:
The Debug Error message box should be expected.