fork(1) download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <exception>
  4.  
  5. #define TEST_TERMINATE
  6.  
  7. void my_terminate()
  8. {
  9. std::cout << "terminate!" << std::endl;
  10. std::abort();
  11. }
  12. void my_unexpected()
  13. {
  14. std::cout << "unexpected!" << std::endl;
  15. std::abort();
  16. }
  17.  
  18. void foo() throw(int)
  19. {
  20. throw "unexpected will be called.";
  21. }
  22.  
  23. int main()
  24. {
  25. std::set_terminate(my_terminate);
  26. std::set_unexpected(my_unexpected);
  27.  
  28. #ifdef TEST_TERMINATE
  29. throw 1;
  30. #else
  31. foo();
  32. #endif
  33. }
  34.  
Runtime error #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
terminate!