fork download
  1. // bad_array_new_length example
  2. #include <iostream> // std::cout
  3. #include <exception> // std::exception
  4. #include <new> // std::bad_array_new_length
  5.  
  6. int main() {
  7. try {
  8. int* p = new int[-1];
  9. } catch (std::bad_array_new_length& e) {
  10. std::cerr << "bad_array_new_length caught: " << e.what() << '\n';
  11. } catch (std::exception& e) { // older compilers may throw other exceptions:
  12. std::cerr << "some other standard exception caught: " << e.what() << '\n';
  13. }
  14. }
Success #stdin #stdout #stderr 0s 3268KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
bad_array_new_length caught: std::bad_array_new_length