fork(21) 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. raii_test t;
  21. int* p = new int[-1]; // throws bad_array_new_length exception
  22. }
Runtime error #stdin #stdout #stderr 0s 3460KB
stdin
Standard input is empty
stdout
Ctor
stderr
terminate called after throwing an instance of 'std::bad_array_new_length'
  what():  std::bad_array_new_length