Skip to content

Instantly share code, notes, and snippets.

@onqtam
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onqtam/351b4b803bfdc2522793 to your computer and use it in GitHub Desktop.
Save onqtam/351b4b803bfdc2522793 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
try {
char* p = new char[10485760000];
delete [] p;
cout << "alloced!" << endl;
} catch(std::exception& e) {
cout << e.what() << endl;
} catch(...) {
cout << "something!" << endl;
}
try {
*((char*)0) = 4;
cout << "derefed!" << endl;
} catch(std::exception& e) {
cout << e.what() << endl;
} catch(...) {
cout << "something!" << endl;
}
try {
int a = 5 / 0;
cout << "divided!" << endl;
} catch(std::exception& e) {
cout << e.what() << endl;
} catch(...) {
cout << "something!" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment