Skip to content

Commit 6d8f4f3

Browse files
nicer fatal error handling
1 parent a89e7e5 commit 6d8f4f3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

game/main.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,38 @@
55
#include <memory>
66
#include <stdexcept>
77

8+
#if _WIN32
9+
#include <Windows.h>
10+
11+
static void show_error(const char *title, const char *message)
12+
{
13+
fprintf(stderr, "%s: %s\n", title, message);
14+
MessageBox(NULL, message, title, MB_ICONERROR | MB_OK);
15+
}
16+
#else
17+
#include <SDL2/SDL_messagebox.h>
18+
19+
static void show_error(const char *title, const char *message)
20+
{
21+
fprintf(stderr, "%s: %s\n", title, message);
22+
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL);
23+
}
24+
#endif
25+
826
int main(int argc, char **argv)
927
{
1028
try {
1129
std::unique_ptr<aoe::Engine> eng(new aoe::Engine());
1230
return eng->mainloop();
13-
#if 0
31+
#if (defined(_DEBUG) && !_DEBUG) || (defined(NDEBUG) && !NDEBUG)
1432
} catch (const std::runtime_error &e) {
15-
fprintf(stderr, "runtime error: %s\n", e.what());
33+
show_error("Fatal Runtime Error", e.what());
1634
} catch (const std::exception &e) {
17-
fprintf(stderr, "internal error: %s\n", e.what());
35+
show_error("Fatal Internal Error", e.what());
1836
#endif
1937
} catch (int v) {
38+
// a la python: interpret as exit code
39+
// so we can do something 'clean' like: throw 0;
2040
return v;
2141
}
2242
return 1;

0 commit comments

Comments
 (0)