Revert "Fix reporting unhandled exceptions in MSVC"
This reverts commit 4d3a0b6602
.
Conflicts:
src/app/main.cpp
master
parent
65d26733fa
commit
551710646b
|
@ -135,45 +135,34 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
|
||||||
InitializeEventTypeTexts();
|
InitializeEventTypeTexts();
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
try
|
CApplication app(systemUtils.get()); // single instance of the application
|
||||||
|
|
||||||
|
ParseArgsStatus status = app.ParseArguments(argc, argv);
|
||||||
|
if (status == PARSE_ARGS_FAIL)
|
||||||
{
|
{
|
||||||
CApplication app(systemUtils.get()); // single instance of the application
|
systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
|
||||||
|
return app.GetExitCode();
|
||||||
ParseArgsStatus status = app.ParseArguments(argc, argv);
|
|
||||||
if (status == PARSE_ARGS_FAIL)
|
|
||||||
{
|
|
||||||
systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", "Invalid commandline arguments!\n");
|
|
||||||
return app.GetExitCode();
|
|
||||||
}
|
|
||||||
else if (status == PARSE_ARGS_HELP)
|
|
||||||
{
|
|
||||||
return app.GetExitCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!app.Create())
|
|
||||||
{
|
|
||||||
code = app.GetExitCode();
|
|
||||||
if (code != 0 && !app.GetErrorMessage().empty())
|
|
||||||
{
|
|
||||||
systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app.GetErrorMessage());
|
|
||||||
}
|
|
||||||
logger.Info("Didn't run main loop. Exiting with code %d\n", code);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = app.Run();
|
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
else if (status == PARSE_ARGS_HELP)
|
||||||
{
|
{
|
||||||
CSignalHandlers::HandleUncaughtException(e);
|
return app.GetExitCode();
|
||||||
}
|
}
|
||||||
catch (...)
|
|
||||||
|
if (! app.Create())
|
||||||
{
|
{
|
||||||
CSignalHandlers::HandleOtherUncaughtException();
|
code = app.GetExitCode();
|
||||||
|
if (code != 0 && !app.GetErrorMessage().empty())
|
||||||
|
{
|
||||||
|
systemUtils->SystemDialog(SDT_ERROR, "COLOBOT - Fatal Error", app.GetErrorMessage());
|
||||||
|
}
|
||||||
|
logger.Info("Didn't run main loop. Exiting with code %d\n", code);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = app.Run();
|
||||||
|
|
||||||
logger.Info("Exiting with code %d\n", code);
|
logger.Info("Exiting with code %d\n", code);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ void CSignalHandlers::Init(CSystemUtils* systemUtils)
|
||||||
signal(SIGABRT, SignalHandler);
|
signal(SIGABRT, SignalHandler);
|
||||||
signal(SIGFPE, SignalHandler);
|
signal(SIGFPE, SignalHandler);
|
||||||
signal(SIGILL, SignalHandler);
|
signal(SIGILL, SignalHandler);
|
||||||
|
std::set_terminate(UnhandledExceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSignalHandlers::SignalHandler(int sig)
|
void CSignalHandlers::SignalHandler(int sig)
|
||||||
|
@ -74,23 +75,29 @@ std::string demangle(const char* name) {
|
||||||
#else
|
#else
|
||||||
// For MSVC and others
|
// For MSVC and others
|
||||||
// In MSVC typeinfo(e).name() should be already demangled
|
// In MSVC typeinfo(e).name() should be already demangled
|
||||||
std::string demangle(const char* name)
|
std::string demangle(const char* name) {
|
||||||
{
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CSignalHandlers::HandleUncaughtException(const std::exception& e)
|
void CSignalHandlers::UnhandledExceptionHandler()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::exception_ptr exptr = std::current_exception();
|
||||||
ss << "Type: " << demangle(typeid(e).name()) << std::endl;
|
try
|
||||||
ss << "Message: " << e.what();
|
{
|
||||||
ReportError(ss.str());
|
std::rethrow_exception(exptr);
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
void CSignalHandlers::HandleOtherUncaughtException()
|
{
|
||||||
{
|
std::stringstream ss;
|
||||||
ReportError("Unknown unhandled exception (not inherited from std::exception)");
|
ss << "Type: " << demangle(typeid(e).name()) << std::endl;
|
||||||
|
ss << "Message: " << e.what();
|
||||||
|
ReportError(ss.str());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
ReportError("Unknown unhandled exception (not inherited from std::exception)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSignalHandlers::ReportError(const std::string& errorMessage)
|
void CSignalHandlers::ReportError(const std::string& errorMessage)
|
||||||
|
|
|
@ -28,9 +28,6 @@ class CSignalHandlers
|
||||||
public:
|
public:
|
||||||
static void Init(CSystemUtils* systemUtils);
|
static void Init(CSystemUtils* systemUtils);
|
||||||
|
|
||||||
static void HandleUncaughtException(const std::exception& e);
|
|
||||||
static void HandleOtherUncaughtException();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void SignalHandler(int sig);
|
static void SignalHandler(int sig);
|
||||||
static void UnhandledExceptionHandler();
|
static void UnhandledExceptionHandler();
|
||||||
|
|
Loading…
Reference in New Issue