show the unhandled exceptions in debug build instead of silently eating them
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46490 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -519,10 +519,13 @@ should return $0$ in case of successful termination.
|
|||||||
|
|
||||||
This function is called when an unhandled C++ exception occurs inside
|
This function is called when an unhandled C++ exception occurs inside
|
||||||
\helpref{OnRun()}{wxapponrun} (the exceptions which occur during the program
|
\helpref{OnRun()}{wxapponrun} (the exceptions which occur during the program
|
||||||
startup and shutdown might not be caught at all).
|
startup and shutdown might not be caught at all). Notice that by now the main
|
||||||
Note that the exception type is lost by now, so if you want to really handle
|
event loop has been terminated and the program will exit, if you want to
|
||||||
the exception you should override \helpref{OnRun()}{wxapponrun} and put a
|
prevent this from happening (i.e. continue running after catching an exception)
|
||||||
try/catch clause around the call to the base class version there.
|
you need to override \helpref{OnExceptionInMainLoop}{wxapponexceptioninmainloop}.
|
||||||
|
|
||||||
|
The default implementation shows information about the exception in debug build
|
||||||
|
but does nothing in the release build.
|
||||||
|
|
||||||
|
|
||||||
\membersection{wxApp::ProcessMessage}\label{wxappprocessmessage}
|
\membersection{wxApp::ProcessMessage}\label{wxappprocessmessage}
|
||||||
|
@@ -197,10 +197,10 @@ public:
|
|||||||
wxEvent& event) const;
|
wxEvent& event) const;
|
||||||
|
|
||||||
// Called when an unhandled C++ exception occurs inside OnRun(): note that
|
// Called when an unhandled C++ exception occurs inside OnRun(): note that
|
||||||
// the exception type is lost by now, so if you really want to handle the
|
// the main event loop has already terminated by now and the program will
|
||||||
// exception you should override OnRun() and put a try/catch around
|
// exit, if you need to really handle the exceptions you need to override
|
||||||
// MainLoop() call there or use OnExceptionInMainLoop()
|
// OnExceptionInMainLoop()
|
||||||
virtual void OnUnhandledException() { }
|
virtual void OnUnhandledException();
|
||||||
#endif // wxUSE_EXCEPTIONS
|
#endif // wxUSE_EXCEPTIONS
|
||||||
|
|
||||||
// event processing functions
|
// event processing functions
|
||||||
|
@@ -45,6 +45,11 @@
|
|||||||
#include "wx/ptr_scpd.h"
|
#include "wx/ptr_scpd.h"
|
||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
|
|
||||||
|
#if wxUSE_EXCEPTIONS && wxUSE_STL
|
||||||
|
#include <exception>
|
||||||
|
#include <typeinfo>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !defined(__WXMSW__) || defined(__WXMICROWIN__)
|
#if !defined(__WXMSW__) || defined(__WXMICROWIN__)
|
||||||
#include <signal.h> // for SIGTRAP used by wxTrap()
|
#include <signal.h> // for SIGTRAP used by wxTrap()
|
||||||
#endif //Win/Unix
|
#endif //Win/Unix
|
||||||
@@ -414,12 +419,38 @@ wxAppConsoleBase::HandleEvent(wxEvtHandler *handler,
|
|||||||
(handler->*func)(event);
|
(handler->*func)(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxAppConsoleBase::OnUnhandledException()
|
||||||
|
{
|
||||||
|
#ifdef __WXDEBUG__
|
||||||
|
// we're called from an exception handler so we can re-throw the exception
|
||||||
|
// to recover its type
|
||||||
|
wxString what;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
#if wxUSE_STL
|
||||||
|
catch ( std::exception& e )
|
||||||
|
{
|
||||||
|
what.Printf("std::exception of type \"%s\", what() = \"%s\"",
|
||||||
|
typeid(e).name(), e.what());
|
||||||
|
}
|
||||||
|
#endif // wxUSE_STL
|
||||||
|
catch ( ... )
|
||||||
|
{
|
||||||
|
what = "unknown exception";
|
||||||
|
}
|
||||||
|
|
||||||
|
wxMessageOutputBest().Printf(
|
||||||
|
"*** Caught unhandled %s; terminating\n", what
|
||||||
|
);
|
||||||
|
#endif // __WXDEBUG__
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// exceptions support
|
// exceptions support
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_EXCEPTIONS
|
|
||||||
|
|
||||||
bool wxAppConsoleBase::OnExceptionInMainLoop()
|
bool wxAppConsoleBase::OnExceptionInMainLoop()
|
||||||
{
|
{
|
||||||
throw;
|
throw;
|
||||||
@@ -430,9 +461,6 @@ bool wxAppConsoleBase::OnExceptionInMainLoop()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_EXCEPTIONS
|
|
||||||
|
|
||||||
|
|
||||||
#endif // wxUSE_EXCEPTIONS
|
#endif // wxUSE_EXCEPTIONS
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user