improve error msg reliability

This commit is contained in:
Akash Mozumdar 2018-10-15 06:46:02 -04:00
parent 4adf820d58
commit abba2d77e3

View File

@ -2,6 +2,14 @@
#include <sstream> #include <sstream>
#include <QApplication> #include <QApplication>
char* GetCppExceptionInfo(EXCEPTION_POINTERS* exception)
{
// See https://blogs.msdn.microsoft.com/oldnewthing/20100730-00/?p=13273
// Not very reliable so use __try
__try { return ((char****)exception->ExceptionRecord->ExceptionInformation[2])[3][1][1] + 8; }
__except (EXCEPTION_EXECUTE_HANDLER) { return "Could not find"; }
}
LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* exception) LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* exception)
{ {
MEMORY_BASIC_INFORMATION info = {}; MEMORY_BASIC_INFORMATION info = {};
@ -15,11 +23,9 @@ LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* exception)
L"Error address: " << (uint64_t)exception->ExceptionRecord->ExceptionAddress << std::endl << L"Error address: " << (uint64_t)exception->ExceptionRecord->ExceptionAddress << std::endl <<
L"Error in module: " << moduleName << std::endl; L"Error in module: " << moduleName << std::endl;
#ifndef _WIN64 if (exception->ExceptionRecord->ExceptionCode == 0xE06D7363)
// See https://blogs.msdn.microsoft.com/oldnewthing/20100730-00/?p=13273 errorMsg << "Additional info: " << GetCppExceptionInfo(exception) << std::endl;
if (exception->ExceptionRecord->ExceptionCode == 0xE06D7363 && exception->ExceptionRecord->ExceptionInformation[2])
errorMsg << "Additional info: " << ((char****)exception->ExceptionRecord->ExceptionInformation[2])[3][1][1] + 8 << std::endl;
#endif
for (int i = 0; i < exception->ExceptionRecord->NumberParameters; ++i) for (int i = 0; i < exception->ExceptionRecord->NumberParameters; ++i)
errorMsg << L"Additional info: " << exception->ExceptionRecord->ExceptionInformation[i] << std::endl; errorMsg << L"Additional info: " << exception->ExceptionRecord->ExceptionInformation[i] << std::endl;