Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Crash handler

(1/1)

Alpha:
In our crash handler, we use wxDebugReport::Process() which according to documentation, does basically nothing.  Is that intended here?

--- Code: ---void CodeBlocksApp::OnFatalException()
{
#if wxUSE_DEBUGREPORT && wxUSE_XML && wxUSE_ON_FATAL_EXCEPTION
    wxDebugReport report;
    wxDebugReportPreviewStd preview;

    report.AddAll();
    if ( preview.Show(report) )
        report.Process();
#else
    cbMessageBox(wxString::Format(_("Something has gone wrong inside %s and it will terminate immediately.\n"
                                    "We are sorry for the inconvenience..."), appglobals::AppName.wx_str()));
#endif
}

--- End code ---

Is there any reason the crash handler should not attempt to save files?

--- Code: ---Index: src/src/app.cpp
===================================================================
--- src/src/app.cpp (revision 9491)
+++ src/src/app.cpp (working copy)
@@ -848,6 +848,29 @@
     cbMessageBox(wxString::Format(_("Something has gone wrong inside %s and it will terminate immediately.\n"
                                     "We are sorry for the inconvenience..."), appglobals::AppName.wx_str()));
 #endif
+    // try to save files
+    EditorManager* edMan = Manager::Get()->GetEditorManager();
+    wxString fileList;
+    for (int i = 0; i < edMan->GetEditorsCount(); ++i)
+    {
+        cbEditor* ed = edMan->GetBuiltinEditor(i);
+        if (ed && ed->GetModified())
+        {
+            wxString crashFn;
+            for (int j = 0; j < 99; ++j)
+            {
+                crashFn = ed->GetFilename() + wxString::Format(wxT(".cb_crash_%02d"), j);
+                if (!wxFileExists(crashFn))
+                    break;
+            }
+            if (cbSaveToFile(crashFn, ed->GetControl()->GetText(), ed->GetEncoding(), ed->GetUseBom()))
+                fileList += _("\n(success)  ") + crashFn;
+            else
+                fileList += _("\n(failure)  ") + crashFn;
+        }
+    }
+    if (!fileList.IsEmpty())
+        cbMessageBox(_("Attempted recovery of:") + fileList, _("Code::Blocks crash handler"));
 }
 
 int CodeBlocksApp::BatchJob()

--- End code ---

oBFusCATed:

--- Quote from: Alpha on December 12, 2013, 01:38:39 am ---Is there any reason the crash handler should not attempt to save files?

--- End quote ---
Because it is dangerous maybe...

thomas:
If that is still the crash handler that I wrote about 5-6 years ago (and which was by default disabled) then it is likely that this call was added because something didn't work otherwise (I sure didn't know about that function, so if it's there, it probably came from a patch to fix an issue).

If that's a different implementation written by someone else, forget the last paragraph.

About saving files from the crash handler, please don't do that. You don't know what you're saving when the application is crashing. This is asking for trouble (also, the goal should be not to have any crashes, not to make crashes feature-rich).

Jenna:

--- Quote from: Alpha on December 12, 2013, 01:38:39 am ---In our crash handler, we use wxDebugReport::Process() which according to documentation, does basically nothing.  Is that intended here?

--- End quote ---

--- Quote from: http://docs.wxwidgets.org/stable/classwx_debug_report.html#a3ec35bb65b88aac386a399b27ef940a5 ---bool wxDebugReport::Process    ()    
Processes this report: the base class simply notifies the user that the report has been generated.
This is usually not enough – instead you should override this method to do something more useful to you.

--- End quote ---
Notfying the user is not nothing.
At least on Linux it pops up dialog and gives me the option to view the crash-report and tells me where it is saved.
The greatest problem is, that the really annoying crashes happen without this dialog, probably because the gui has been destroyed already, or the crash is "too hard".

Alpha:

--- Quote from: jens on December 12, 2013, 01:39:02 pm ---At least on Linux it pops up dialog and gives me the option to view the crash-report and tells me where it is saved.

--- End quote ---
The dialog I receive on under Linux is from wxDebugReportPreviewStd::Show().  Regardless of if I have or delete the line report.Process(), I cannot find any functional difference.

Navigation

[0] Message Index

Go to full version