Fix reporting unhandled exceptions in MSVC
For some reason set_terminate() doesn't work with MSVC2013master
parent
0c670e7699
commit
4d3a0b6602
|
@ -135,6 +135,8 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
|
||||||
InitializeEventTypeTexts();
|
InitializeEventTypeTexts();
|
||||||
|
|
||||||
int code = 0;
|
int code = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
CApplication app(systemUtils.get()); // single instance of the application
|
CApplication app(systemUtils.get()); // single instance of the application
|
||||||
|
@ -169,9 +171,17 @@ int SDL_MAIN_FUNC(int argc, char *argv[])
|
||||||
if (!restarting)
|
if (!restarting)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
CSignalHandlers::HandleUncaughtException(e);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
CSignalHandlers::HandleOtherUncaughtException();
|
||||||
|
}
|
||||||
|
|
||||||
logger.Info("Exiting with code %d\n", code);
|
logger.Info("Exiting with code %d\n", code);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,6 @@ 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)
|
||||||
|
@ -73,30 +72,24 @@ 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::UnhandledExceptionHandler()
|
void CSignalHandlers::HandleUncaughtException(const std::exception& e)
|
||||||
{
|
|
||||||
std::exception_ptr exptr = std::current_exception();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
std::rethrow_exception(exptr);
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Type: " << demangle(typeid(e).name()) << std::endl;
|
ss << "Type: " << demangle(typeid(e).name()) << std::endl;
|
||||||
ss << "Message: " << e.what();
|
ss << "Message: " << e.what();
|
||||||
ReportError(ss.str());
|
ReportError(ss.str());
|
||||||
}
|
}
|
||||||
catch (...)
|
|
||||||
|
void CSignalHandlers::HandleOtherUncaughtException()
|
||||||
{
|
{
|
||||||
ReportError("Unknown unhandled exception (not inherited from std::exception)");
|
ReportError("Unknown unhandled exception (not inherited from std::exception)");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CSignalHandlers::ReportError(const std::string& errorMessage)
|
void CSignalHandlers::ReportError(const std::string& errorMessage)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,9 @@ 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