fork(11) download
  1. #include <iostream> // std::cout
  2. #include <exception> // std::exception
  3. #include <new> // std::bad_array_new_length
  4. class raii_test
  5. {
  6. public:
  7. raii_test()
  8. {
  9. // assume some file is opened
  10. std::cout<<"Ctor\n";
  11. }
  12. ~raii_test()
  13. {
  14. // assume that file is closed
  15. std::cout<<"Dtor\n";
  16. }
  17. };
  18.  
  19. int main() {
  20. try {
  21. raii_test t;
  22.  
  23. int* p = new int[-1]; // throws bad_array_new_length exception
  24. }
  25. catch (...) {
  26. std::cout << "Exception was thrown\n";
  27. }
  28. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Ctor
Dtor
Exception was thrown