From bced30d1e3fbd79bb7595406983e8bc32775b624 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 23 Nov 2018 10:18:14 +0100 Subject: [PATCH] - made CDoomError inherit from std::exception so that the main catch block can also deal with exceptions thrown by the STL. - Also do not ignore empty exception messages as irrelevant. The only irrelevant exception type is CNoRunExit. --- src/doomerrors.h | 14 ++++++++++++-- src/posix/cocoa/i_main_except.cpp | 6 +++--- src/posix/i_steam.cpp | 4 ++-- src/posix/sdl/i_main.cpp | 6 +++--- src/win32/i_main.cpp | 9 +++++---- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/doomerrors.h b/src/doomerrors.h index c389c6b05..a7ec02654 100644 --- a/src/doomerrors.h +++ b/src/doomerrors.h @@ -37,10 +37,11 @@ #include #include +#include #define MAX_ERRORTEXT 1024 -class CDoomError +class CDoomError : public std::exception { public: CDoomError () @@ -69,13 +70,22 @@ public: else return NULL; } + char const *what() const override + { + return m_Message; + } + protected: char m_Message[MAX_ERRORTEXT]; }; -class CNoRunExit : public CDoomError +class CNoRunExit : public std::exception { +public: + CNoRunExit() : std::exception("NoRunExit") + { + } }; class CRecoverableError : public CDoomError diff --git a/src/posix/cocoa/i_main_except.cpp b/src/posix/cocoa/i_main_except.cpp index 5c3785588..a61eca2cc 100644 --- a/src/posix/cocoa/i_main_except.cpp +++ b/src/posix/cocoa/i_main_except.cpp @@ -46,13 +46,13 @@ void OriginalMainExcept(int argc, char** argv) { OriginalMainTry(argc, argv); } - catch(const CDoomError& error) + catch(const std::exception& error) { - const char* const message = error.GetMessage(); + const char* const message = error.what(); if (NULL != message) { - fprintf(stderr, "%s\n", message); + if (strcmp(message, "NoRunExit")) fprintf(stderr, "%s\n", message); Mac_I_FatalError(message); } diff --git a/src/posix/i_steam.cpp b/src/posix/i_steam.cpp index 29dc9b845..dccadb021 100644 --- a/src/posix/i_steam.cpp +++ b/src/posix/i_steam.cpp @@ -178,7 +178,7 @@ TArray I_GetSteamPath() { SteamInstallFolders = ParseSteamRegistry(regPath); } - catch(class CDoomError &error) + catch(class CRecoverableError &error) { // If we can't parse for some reason just pretend we can't find anything. return result; @@ -201,7 +201,7 @@ TArray I_GetSteamPath() { SteamInstallFolders = ParseSteamRegistry(regPath); } - catch(class CDoomError &error) + catch(class CRecoverableError &error) { // If we can't parse for some reason just pretend we can't find anything. return result; diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index 38f035515..8e7230777 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -258,11 +258,11 @@ int main (int argc, char **argv) C_InitConsole (80*8, 25*8, false); D_DoomMain (); } - catch (class CDoomError &error) + catch (std::exception &error) { I_ShutdownJoysticks(); - if (error.GetMessage ()) - fprintf (stderr, "%s\n", error.GetMessage ()); + if (error.what () && strcmp(error.what(), "NoRunExit")) + fprintf (stderr, "%s\n", error.what ()); #ifdef __APPLE__ Mac_I_FatalError(error.GetMessage()); diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index b1d7a7bb7..6a75a597a 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -1048,21 +1048,22 @@ void DoMain (HINSTANCE hInstance) } exit(0); } - catch (class CDoomError &error) + catch (std::exception &error) { I_ShutdownGraphics (); RestoreConView (); S_StopMusic(true); I_FlushBufferedConsoleStuff(); - if (error.GetMessage ()) + auto msg = error.what(); + if (strcmp(msg, "NoRunExit")) { if (!batchrun) { - ShowErrorPane(error.GetMessage()); + ShowErrorPane(msg); } else { - Printf("%s\n", error.GetMessage()); + Printf("%s\n", msg); } } exit (-1);