Skip to content
This repository was archived by the owner on Oct 16, 2021. It is now read-only.

Commit c5cb98f

Browse files
committed
Print informative message on unhandled C++ exceptions
1 parent c1945bd commit c5cb98f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Source/Exception.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#pragma warning (push)
2323
#pragma warning (disable:4091) // a microsoft header has warnings. Very nice.
2424
#include <Dbghelp.h>
25+
#include <exception>
26+
#include <Source/str_conv/str_conv.hpp>
27+
2528
#pragma warning (pop)
2629
#include "Exception.h"
2730
#include "../version.h"
@@ -118,10 +121,19 @@ static LONG WINAPI ExceptionHandler(__in struct _EXCEPTION_POINTERS *ep)
118121
// Display a message
119122
CString text;
120123
text.Format(_T("This application has encountered a problem and needs to close.\n\n"));
121-
text.AppendFormat(_T("Unhandled exception %X.\n\n"), ep->ExceptionRecord->ExceptionCode);
124+
if (ep) {
125+
if (ep->ExceptionRecord->ExceptionCode == 0xE06D7363) { // // //
126+
auto msg = conv::to_t(reinterpret_cast<const std::exception *>(ep->ExceptionRecord->ExceptionInformation[1])->what());
127+
text.AppendFormat(_T("Unhandled C++ exception: \"%.*s\".\n\n"), msg.size(), msg.data());
128+
}
129+
else {
130+
text.AppendFormat(_T("Unhandled exception %X.\n\n"), ep->ExceptionRecord->ExceptionCode);
131+
}
132+
} else {
133+
text.AppendFormat(_T("Unhandled exception (null, this should not happen, please contact jimbo1qaz).\n\n"));
134+
}
122135
text.AppendFormat(_T("A memory dump file has been created (%s), please include this if you file a bug report!\n\n"), LPCTSTR(MinidumpFile));
123136
text.AppendFormat(_T("Attempting to save current module as %s."), LPCTSTR(DocDumpFile));
124-
// text.Append(_T("Application will now close."));
125137
AfxMessageBox(text, MB_ICONSTOP);
126138

127139
// Try to save the document

0 commit comments

Comments
 (0)