Skip to content

Instantly share code, notes, and snippets.

@jl2
Created September 3, 2010 16:55
Show Gist options
  • Save jl2/564172 to your computer and use it in GitHub Desktop.
Save jl2/564172 to your computer and use it in GitHub Desktop.
// Interesting C++ exception handling technique?
#include <iostream>
#include <cstdlib>
#include <ctime>
void damn() {
std::cout << "Damn\n";
}
void crap() {
std::cout << "crap\n";
}
typedef void (*handler)(void);
int main() {
srand(time(0));
try {
std::cout << "about to throw a random exception:\n";
if (rand()%2) {
throw damn;
} else {
throw crap;
}
} catch (handler err) {
err();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment