Skip to content

Instantly share code, notes, and snippets.

@dobrokot
Created July 9, 2013 10:45
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 dobrokot/5956463 to your computer and use it in GitHub Desktop.
Save dobrokot/5956463 to your computer and use it in GitHub Desktop.
exceptions.cpp
#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