- 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.
This commit is contained in:
Christoph Oelckers 2018-11-23 10:18:14 +01:00
parent d4e630c127
commit bced30d1e3
5 changed files with 25 additions and 14 deletions

View file

@ -37,10 +37,11 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <exception>
#define MAX_ERRORTEXT 1024 #define MAX_ERRORTEXT 1024
class CDoomError class CDoomError : public std::exception
{ {
public: public:
CDoomError () CDoomError ()
@ -69,13 +70,22 @@ public:
else else
return NULL; return NULL;
} }
char const *what() const override
{
return m_Message;
}
protected: protected:
char m_Message[MAX_ERRORTEXT]; char m_Message[MAX_ERRORTEXT];
}; };
class CNoRunExit : public CDoomError class CNoRunExit : public std::exception
{ {
public:
CNoRunExit() : std::exception("NoRunExit")
{
}
}; };
class CRecoverableError : public CDoomError class CRecoverableError : public CDoomError

View file

@ -46,13 +46,13 @@ void OriginalMainExcept(int argc, char** argv)
{ {
OriginalMainTry(argc, 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) if (NULL != message)
{ {
fprintf(stderr, "%s\n", message); if (strcmp(message, "NoRunExit")) fprintf(stderr, "%s\n", message);
Mac_I_FatalError(message); Mac_I_FatalError(message);
} }

View file

@ -178,7 +178,7 @@ TArray<FString> I_GetSteamPath()
{ {
SteamInstallFolders = ParseSteamRegistry(regPath); 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. // If we can't parse for some reason just pretend we can't find anything.
return result; return result;
@ -201,7 +201,7 @@ TArray<FString> I_GetSteamPath()
{ {
SteamInstallFolders = ParseSteamRegistry(regPath); 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. // If we can't parse for some reason just pretend we can't find anything.
return result; return result;

View file

@ -258,11 +258,11 @@ int main (int argc, char **argv)
C_InitConsole (80*8, 25*8, false); C_InitConsole (80*8, 25*8, false);
D_DoomMain (); D_DoomMain ();
} }
catch (class CDoomError &error) catch (std::exception &error)
{ {
I_ShutdownJoysticks(); I_ShutdownJoysticks();
if (error.GetMessage ()) if (error.what () && strcmp(error.what(), "NoRunExit"))
fprintf (stderr, "%s\n", error.GetMessage ()); fprintf (stderr, "%s\n", error.what ());
#ifdef __APPLE__ #ifdef __APPLE__
Mac_I_FatalError(error.GetMessage()); Mac_I_FatalError(error.GetMessage());

View file

@ -1048,21 +1048,22 @@ void DoMain (HINSTANCE hInstance)
} }
exit(0); exit(0);
} }
catch (class CDoomError &error) catch (std::exception &error)
{ {
I_ShutdownGraphics (); I_ShutdownGraphics ();
RestoreConView (); RestoreConView ();
S_StopMusic(true); S_StopMusic(true);
I_FlushBufferedConsoleStuff(); I_FlushBufferedConsoleStuff();
if (error.GetMessage ()) auto msg = error.what();
if (strcmp(msg, "NoRunExit"))
{ {
if (!batchrun) if (!batchrun)
{ {
ShowErrorPane(error.GetMessage()); ShowErrorPane(msg);
} }
else else
{ {
Printf("%s\n", error.GetMessage()); Printf("%s\n", msg);
} }
} }
exit (-1); exit (-1);