Created
September 3, 2010 16:55
-
-
Save jl2/564172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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