]> git.saurik.com Git - wxWidgets.git/commitdiff
wxHandleFatalExceptions() added, documented
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 17 Mar 2000 16:55:34 +0000 (16:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 17 Mar 2000 16:55:34 +0000 (16:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6802 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/app.tex
docs/latex/wx/function.tex
include/wx/utils.h
src/common/wincmn.cpp
src/gtk/app.cpp
src/gtk1/app.cpp
src/unix/utilsunx.cpp

index b5e7d313404f89ff0c34b5f86645a0c016be7a7c..ac6b3fb0a8b25705ce4ba42baa1e4f32ec84e3d2 100644 (file)
@@ -233,6 +233,23 @@ If you use this member, you can selectively consume keypress events by calling\r
 \helpref{wxKeyEvent}{wxkeyevent}, \helpref{wxWindow::OnChar}{wxwindowonchar},\rtfsp
 \helpref{wxWindow::OnCharHook}{wxwindowoncharhook}, \helpref{wxDialog::OnCharHook}{wxdialogoncharhook}
 
+\membersection{wxApp::OnFatalException}\label{wxapponfatalexception}
+
+\func{void}{OnFatalException}{\void}
+
+This function may be called if something fatal happens: an unhandled
+exception under Win32 or a a fatal signal under Unix, for example. However,
+this will not happen by default: you have to explicitly call 
+\helpref{wxHandleFatalExcetions}{wxhandlefatalexcetions} to enable this.
+
+Generally speaking, this function should only show a message to the user and
+return. You may attempt to save unsaved data but this is not guaranteed to
+work and, in fact, probably won't.
+
+\wxheading{See also}
+
+\helpref{wxHandleFatalExcetions}{wxhandlefatalexcetions}
+
 \membersection{wxApp::OnIdle}\label{wxapponidle}
 
 \func{void}{OnIdle}{\param{wxIdleEvent\& }{event}}
index 776ed77822a7d073404fdee2e78399861b040b2d..587d32e6e6feb288413b71dbc6c5135069eb44e7 100644 (file)
@@ -1057,6 +1057,14 @@ The clipboard must have previously been opened for this call to succeed.
 
 \section{Miscellaneous functions}\label{miscellany}
 
+\membersection{wxHandleFatalExcetions}\label{wxhandlefatalexcetions}
+
+\func{bool}{wxHandleFatalExcetions}{\param{bool }{doIt = TRUE}}
+
+Enables or disables handling of fatal program exceptions. If {\it doIt} is
+TRUE, \helpref{wxApp::OnFatalException}{wxapponfatalexception} will be called
+before the program crashes. Otherwise, the default behaviour will be restored.
+
 \membersection{::wxNewId}
 
 \func{long}{wxNewId}{\void}
index 09ac220a9ea1491e0eedea64da2e464842c015aa..2eec7b1c11fd2ac7b12f9f01fc9671dffeb8c062 100644 (file)
@@ -193,6 +193,9 @@ WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
 WXDLLEXPORT long wxGetFreeMemory();
 
+// should wxApp::OnFatalException() be called?
+WXDLLEXPORT bool wxHandleFatalExceptions(bool doit = TRUE);
+
 // ----------------------------------------------------------------------------
 // Network and username functions.
 // ----------------------------------------------------------------------------
index 0bc84593e159e79b06398d068959849dd5b079d6..c8885cb0c49ba12fd59e4bcbe0396f06d30593bd 100644 (file)
@@ -41,6 +41,7 @@
     #include "wx/settings.h"
     #include "wx/dialog.h"
     #include "wx/msgdlg.h"
+    #include "wx/statusbr.h"
 #endif //WX_PRECOMP
 
 #if wxUSE_CONSTRAINTS
index 17732ceb90fb3d997917f39ee6c82f5973f46c06..84f625014f42d0170e1442b7667cb0f4fa3fb280 100644 (file)
@@ -29,7 +29,7 @@
 #include "wx/image.h"
 
 #if wxUSE_THREADS
-#include "wx/thread.h"
+    #include "wx/thread.h"
 #endif
 
 #include <unistd.h>
@@ -651,9 +651,7 @@ void wxEntryCleanup()
 
 int wxEntry( int argc, char *argv[] )
 {
-    int err;
-
-    err = wxEntryStart(argc, argv);
+    int err = wxEntryStart(argc, argv);
     if (err)
         return err;
 
index 17732ceb90fb3d997917f39ee6c82f5973f46c06..84f625014f42d0170e1442b7667cb0f4fa3fb280 100644 (file)
@@ -29,7 +29,7 @@
 #include "wx/image.h"
 
 #if wxUSE_THREADS
-#include "wx/thread.h"
+    #include "wx/thread.h"
 #endif
 
 #include <unistd.h>
@@ -651,9 +651,7 @@ void wxEntryCleanup()
 
 int wxEntry( int argc, char *argv[] )
 {
-    int err;
-
-    err = wxEntryStart(argc, argv);
+    int err = wxEntryStart(argc, argv);
     if (err)
         return err;
 
index fb8c58bc9022092d6faa86f42c20a2c9caf3a4b6..a3f3641c03d1e8fb84e0a666153a2bb9b62c2641 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "wx/intl.h"
 #include "wx/log.h"
+#include "wx/app.h"
 
 #include "wx/utils.h"
 #include "wx/process.h"
@@ -785,6 +786,79 @@ wxString wxGetOsDescription()
 #endif
 }
 
+// ----------------------------------------------------------------------------
+// signal handling
+// ----------------------------------------------------------------------------
+
+#if wxUSE_ON_FATAL_EXCEPTION
+
+#include <signal.h>
+
+static void wxFatalSignalHandler(int signal)
+{
+    if ( wxTheApp )
+    {
+        // give the user a chance to do something special about this
+        wxTheApp->OnFatalException();
+    }
+
+    abort();
+}
+
+bool wxHandleFatalExceptions(bool doit)
+{
+    // old sig handlers
+    static bool s_savedHandlers = FALSE;
+    static struct sigaction s_handlerFPE,
+                            s_handlerILL,
+                            s_handlerBUS,
+                            s_handlerSEGV;
+
+    bool ok = TRUE;
+    if ( doit && !s_savedHandlers )
+    {
+        // install the signal handler
+        struct sigaction act;
+
+        // some systems extend it with non std fields, so zero everything
+        memset(&act, 0, sizeof(act));
+
+        act.sa_handler = wxFatalSignalHandler;
+        sigemptyset(&act.sa_mask);
+        act.sa_flags = 0;
+
+        ok &= sigaction(SIGFPE, &act, &s_handlerFPE) == 0;
+        ok &= sigaction(SIGILL, &act, &s_handlerILL) == 0;
+        ok &= sigaction(SIGBUS, &act, &s_handlerBUS) == 0;
+        ok &= sigaction(SIGSEGV, &act, &s_handlerSEGV) == 0;
+        if ( !ok )
+        {
+            wxLogDebug(_T("Failed to install our signal handler."));
+        }
+
+        s_savedHandlers = TRUE;
+    }
+    else if ( s_savedHandlers )
+    {
+        // uninstall the signal handler
+        ok &= sigaction(SIGFPE, &s_handlerFPE, NULL) == 0;
+        ok &= sigaction(SIGILL, &s_handlerILL, NULL) == 0;
+        ok &= sigaction(SIGBUS, &s_handlerBUS, NULL) == 0;
+        ok &= sigaction(SIGSEGV, &s_handlerSEGV, NULL) == 0;
+        if ( !ok )
+        {
+            wxLogDebug(_T("Failed to uninstall our signal handler."));
+        }
+
+        s_savedHandlers = FALSE;
+    }
+    //else: nothing to do
+
+    return ok;
+}
+
+#endif // wxUSE_ON_FATAL_EXCEPTION
+
 // ----------------------------------------------------------------------------
 // error and debug output routines (deprecated, use wxLog)
 // ----------------------------------------------------------------------------