Created
July 9, 2013 10:45
-
-
Save dobrokot/5956463 to your computer and use it in GitHub Desktop.
exceptions.cpp
This file contains 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
#include <iostream> | |
#include <string> | |
#include <stdexcept> | |
#include <stdlib.h> | |
void g(int i) { | |
if (i % 4 == 0 && i % 6 == 0) | |
throw std::logic_error("FATALITY"); | |
if (i % 3 == 0) | |
throw std::runtime_error("expected error"); | |
} | |
void f(int i) { | |
g(i); | |
g(i+1); | |
} | |
int main() { | |
for (int i = 1; i < 20; ++i) { | |
try { | |
f(i); | |
} catch (std::runtime_error &e) { | |
std::cerr << i << " " << e.what() << '\n'; | |
std::cerr << "show must go on" << '\n' << std::flush; | |
//хорошо бы тут ещё в лог callstack распечатать... | |
} catch (std::exception &e) { | |
abort(); | |
//хорошо бы в корке ещё нормальный backtrace... | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment