#include <exception>
#include <new>
#include <iostream>
int main() {
try {
throw ::std::bad_alloc();
} catch(::std::bad_alloc&) {
::std::cout << "::std::bad_alloc\n";
} catch(::std::exception&) {
::std::cout << "::std::exception\n";
}
::std::cout << "\n";
try {
try {
throw ::std::bad_alloc();
} catch(::std::exception& e) {
::std::cout << "rethrowing ::std::bad_alloc as ::std::exception...\n";
throw e;
}
} catch(::std::bad_alloc&) {
::std::cout << "::std::bad_alloc\n";
} catch(::std::exception&) {
::std::cout << "::std::exception\n";
}
::std::cout << "\n";
try {
try {
throw ::std::bad_alloc();
} catch(...) {
::std::cout << "rethrowing ::std::bad_alloc correctly\n";
throw;
}
} catch(::std::bad_alloc&) {
::std::cout << "::std::bad_alloc\n";
} catch(::std::exception&) {
::std::cout << "::std::exception\n";
}
}