-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
I need to get the call stack when a crash occurs.
Our project is using C++/CLI to combine C# and C++ code.
The exception from C# and C++/CLI, we can use try-catch to get the exception.
But the exception from native C++, especially the exception that is considered unrecoverable, or occurs in another thread, like AccessViolationException, StackOverflowException.
int* p = nullptr;
*p = 123;
And I also see when the native exception occurs, the console will print this message and then the app crash:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at <Module>.NativeCppDemo.MyNativeCppTestClass.memberFunctionAddFunCrash(NativeCppDemo.MyNativeCppTestClass*, Int32, Int32)
--------------------------------
at ClrCrashTestNetCore.ClrTest.memberFunAddCrash(Int32, Int32, Boolean)
at CsCrashDemoNetCore.Program.Run()
at CsCrashDemoNetCore.Program.Main(System.String[])
This is the message that I want but I don't know how to get it in the code.
And I found this message when the exception occurs on another thread, it won't print on the console.
Do we have any method to get the exception information from native C++? Like has some interface to get the exception? Or using a profiler can get the call stack?