fork download
  1. #include "iostream"
  2. //#include "conio.h"
  3. #include "exception"
  4. #include "cstdlib"
  5. using namespace std;
  6.  
  7. void myunexpected ()
  8. {
  9. cerr << "unexpected called\n";
  10. throw 0; // throws int (in exception-specification)
  11. }
  12.  
  13. void myfunction () throw (int)
  14. {
  15. throw 'x'; // throws char (not in exception-specification)
  16. }
  17.  
  18. int main (void)
  19. {
  20. set_unexpected (myunexpected);
  21. try
  22. {
  23. myfunction();
  24. }
  25. catch (int) { cerr << "caught int\n"; }
  26. catch (...) { cerr << "caught other exception (non-compliant compiler?)\n"; }
  27. // getch();
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty