In C++11 destructors default to noexcept so you have to go out of your way to make them throw. See throwing a vector in a destructor.
#include <exception>
#include <iostream>
#include <vector>
// Note the braces
void exception1() try { throw 1; } catch (int e) {
std::cout << "Caught " << e << std::endl;
} catch (const std::out_of_range &oor) {
std::cout << "Caught OOR\n" << oor.what() << std::endl;
} catch (const std::exception &e) {
std::cout << "Caught " << e.what() << std::endl;
} catch (...) {
std::cout << "Caught ellipsis" << std::endl;
}
void exception2() {
using namespace std;
// Simple
try {
throw 2;
} catch (int e) {
cout << "Caught exception " << e << endl;
}
try {
vector<int> vec(5);
vec.at(6);
} catch (exception &e) {
cout << "Caught exception " << e.what() << endl;
}
}
int main() {
exception1();
exception2();
}