const char* ExceptionBase::what() const noexcept { if (!m_what.empty()) return m_what.c_str(); if(m_sysErrno != 0) m_what = format("[{execptionName}], msg:[{m_msg}], file:[{m_file}+{m_line}], fun:[{m_func}], errno:[{m_sysErrno} {strerr}]", exceptionName(), m_msg, m_file, m_line, m_func, m_sysErrno, ::strerror(m_sysErrno)); else m_what = format("[{execptionName}], msg:[{m_msg}], file:[{m_file}+{m_line}], fun:[{m_func}]", exceptionName(), m_msg, m_file, m_line, m_func); return m_what.c_str(); }
LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception) { logGlobal->errorStream() << "Disaster happened."; PEXCEPTION_RECORD einfo = exception->ExceptionRecord; logGlobal->errorStream() << "Reason: 0x" << std::hex << einfo->ExceptionCode << " - " << exceptionName(einfo->ExceptionCode) << " at " << std::setfill('0') << std::setw(4) << exception->ContextRecord->SegCs << ":" << (void*)einfo->ExceptionAddress; if (einfo->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { logGlobal->errorStream() << "Attempt to " << (einfo->ExceptionInformation[0] == 1 ? "write to " : "read from ") << "0x" << std::setw(8) << (void*)einfo->ExceptionInformation[1]; } const DWORD threadId = ::GetCurrentThreadId(); logGlobal->errorStream() << "Thread ID: " << threadId << " [" << std::dec << std::setw(0) << threadId << "]"; #ifndef __MINGW32__ //exception info to be placed in the dump MINIDUMP_EXCEPTION_INFORMATION meinfo = {threadId, exception, TRUE}; //create file where dump will be placed char *mname = nullptr; char buffer[MAX_PATH + 1]; HMODULE hModule = nullptr; GetModuleFileNameA(hModule, buffer, MAX_PATH); mname = strrchr(buffer, '\\'); if (mname != 0) mname++; else mname = buffer; strcat(mname, "_crashinfo.dmp"); HANDLE dfile = CreateFileA(mname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); logGlobal->errorStream() << "Crash info will be put in " << mname; MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, MiniDumpWithDataSegs, &meinfo, 0, 0); #endif MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR); return EXCEPTION_EXECUTE_HANDLER; }