From b7897cddf274ccf8f348069e985879842a3bd6e4 Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Sun, 24 Mar 2024 22:00:22 -0700 Subject: [PATCH] show uncaught exception messages on windows --- src/Main.cc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Main.cc b/src/Main.cc index 1bf0b2b3..9387cbbc 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -2650,6 +2650,30 @@ int main(int argc, char** argv) { log_error("Unknown or invalid action; try --help"); return 1; } +#ifdef PHOSG_WINDOWS + // Cygwin just gives a stackdump when an exception falls out of main(), so + // unlike Linux and macOS, we have to manually catch exceptions here just to + // see what the exception message was. + try { + a->run(args); + } catch (const cannot_open_file& e) { + log_error("Top-level exception (cannot_open_file): %s", e.what()); + throw; + } catch (const invalid_argument& e) { + log_error("Top-level exception (invalid_argument): %s", e.what()); + throw; + } catch (const out_of_range& e) { + log_error("Top-level exception (out_of_range): %s", e.what()); + throw; + } catch (const runtime_error& e) { + log_error("Top-level exception (runtime_error): %s", e.what()); + throw; + } catch (const exception& e) { + log_error("Top-level exception: %s", e.what()); + throw; + } +#else a->run(args); +#endif return 0; }