mardi 19 novembre 2019

Catching segfaults of c++ cli and c++ dlls on a WPF C# application

I have a C# WPF Application running on windows, which utilizes code written in c++ and compiled as dynamic libraries. We have c++-cli code segments for translating data between the C# GUI parts and the C++ engine parts. For unhandled exceptions in the C# part itself, we have added this following code segment:

static void Main(string[] args)
        {
            some code...
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            some code...
        }

private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Logger.Error(e.ExceptionObject.ToString());
        }

This works fine for exceptions thrown from the c++ code, also from the cli code, and of course for the c# code. What we are attempting now is to somehow (if it's possible) catch segfaults or other crashes coming from the c++\cli code? Obviously we can't wrap calls to c++\cli code with "try/catch" because it will not catch crashes of that sort.

I know it's not something we should "aspire" to, and if segfaults occur it's not good, but since our software is used by a couple hundreds of people across the organization, we must have a way to capture these crashes when they happen and the users reports it to us. At the moment, if such crash does happen, it will only generate the regular windows based pop-up box of the crash, and afterwards would simply close the application without any information about the crash logged.

Thanks for any kind of suggestion, and I apologize if there's a mistake in my question. If any clarification is needed, please let me know and I'll do my best to edit.

Aucun commentaire:

Enregistrer un commentaire