I recommend you try __try / __ except
__try { Application::Run(gcnew frmMain()); } __except(EXCEPTION_EXECUTE_HANDLER) { LogAndExit(new Exception("Some Unmanage exception")); }
MSDN documentation here:
http://msdn.microsoft.com/en-us/library/s58ftw19(v=vs.80).aspx
If you want to become very tricky, try double-packing as follows:
__try { try { Application::Run(gcnew frmMain()); } catch(SEHException^ e) { LogAndExit(new Exception("Some Unmanage exception")); } catch(...)
Structured exceptions are wrapped in SEHException ^ in general.
You also need to consider that you can actually catch an exception, but something in your LogAndExit method throws a secondary exception, which actually ends with your program. Try disabling the LogAndExit function and see if you can accidentally crash and not with a standard interrupt message and / or wrap your LogAndExit code in another try / catch that hides any exceptions.
As someone who has made significant contributions to C ++ / CLI, I can sympathize with your dilemma. We hope this solution helps.
Additional MSDN documentation on C ++ / CLI exception handling:
How to identify and install the global exception handler http://msdn.microsoft.com/en-us/library/171ezxzc.aspx
Exception handling in / clr http://msdn.microsoft.com/en-us/library/633chdda.aspx
source share