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.
Edited and added to explain better: I know segfaults and other system-crashes are bad and not something to cause. The thing is, our software is used by 200-something people in the organization who need to develop more code and are using the software to debug and perfect their code. As such, sometimes, their code will have those errors, and not all errors are captured fully by the other people and we are looking for a solution within the code itself to help maintain that, along with copying any errors.
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.
Edit #2: In the native version of our software (which is only a console program without any GUI element) we do have a solution that works. This solution works well in both Windows and Linux distributions of our software, and it is catching the signals and writing the stack trace to the logs before shutting down.