The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[U8.1][C++]UnhandledErrorDetected not firing RRS feed

Answers

  • Solved. __try/__except construct works because it's C/C++ specific (CRT?) and not platform-specific thus can still be used in Universal apps. GetExceptionInformation() also works for the same reason.

    The needed modification to existing app started from DirectX 11 Universal (C++) project template is to move contents of ::Run() (basically your game loop) into another function (for example ::GuardedRun() ) and then call that function inside of a __try block in original ::Run().

    In the matching __except, call your unhandled exception handler function, which should return an INT and take LPEXCEPTION_POINTERS type. Plug in GetExceptionInformation() to get that LPEXCEPTION_POINTERS type value:

    void MyApp::Run() { __try { GuardedRun(); } __except(MyUnhandledExceptionHandler(GetExceptionInformation())) { } } void MyApp::GuardedRun() { // Previous contents of ::Run() moved here. /* Necessary because getting dispatcher used to pump the message loop creates a stack variable which must be destroyed, and apparently using SEH (__try block) prevents the compiler from doing that, so it complains with error. */ } int MyApp::UnhandledExceptionHandler(LPEXCEPTION_POINTERS exceptionInfo) { // Perform logging, write crash dump, etc. // Actually no idea how to do this in WinRT yet.

    return EXCEPTION_EXECUTE_HANDLER; }

    For meaning of EXCEPTION_EXECUTE_HANDLER and more info on SEH, see following:

    https://msdn.microsoft.com/en-us/library/s58ftw19.aspx


    Wednesday, August 5, 2015 9:38 PM

All replies

  • Have you changed the Debug type to Mixed mode? http://blogs.msdn.com/b/visualstudioalm/archive/2013/02/16/mixed-native-and-managed-debugging-improvements-for-windows-store-apps.aspx

    If yes, try to run analysis tools from the Performance and Diagnostic page: https://msdn.microsoft.com/en-us/library/Dn435909.aspx


    Best Regards,
    Please remember to mark the replies as answers if they help

    Wednesday, August 5, 2015 6:38 AM
  • Setting Debug to Mixed didn't make much difference; I wasn't debugging anyway as the unhandled exception handler does not get fired in Debug. Visual Studio will trap crashes when debugging as First Chance Exceptions and breaks instead of letting any handlers execute. I still tried it and ran without debugging in Mixed.

    When I ran the analysis tools it simply recorded application initialization and activation events, with flat lines for CPU and frame rate on all threads. I tried various tools, but the best info I got is a list of all functions called in the entire program, with a tree view showing who called who. With this information I can say for sure my handler was not called, but not why.

    Wednesday, August 5, 2015 5:21 PM
  • I decompiled the Universal binary with Hex Rays and noticed that the CRT startup sequence is making use of unhandled exception handler set by std::set_unexpected and other such functions (std::set_terminate, etc). I also noticed that the DirectX 11 project template I used to start my Universal project does not include boilerplate for __try/__except, another CRT mechanism. See this article: http://www.codeproject.com/Articles/207464/Exception-Handling-in-Visual-Cplusplus

    I will report back if either std::set_unexpected or __try/__except finally succeed in trapping exceptions in my app.

    Wednesday, August 5, 2015 5:55 PM
  • Solved. __try/__except construct works because it's C/C++ specific (CRT?) and not platform-specific thus can still be used in Universal apps. GetExceptionInformation() also works for the same reason.

    The needed modification to existing app started from DirectX 11 Universal (C++) project template is to move contents of ::Run() (basically your game loop) into another function (for example ::GuardedRun() ) and then call that function inside of a __try block in original ::Run().

    In the matching __except, call your unhandled exception handler function, which should return an INT and take LPEXCEPTION_POINTERS type. Plug in GetExceptionInformation() to get that LPEXCEPTION_POINTERS type value:

    void MyApp::Run() { __try { GuardedRun(); } __except(MyUnhandledExceptionHandler(GetExceptionInformation())) { } } void MyApp::GuardedRun() { // Previous contents of ::Run() moved here. /* Necessary because getting dispatcher used to pump the message loop creates a stack variable which must be destroyed, and apparently using SEH (__try block) prevents the compiler from doing that, so it complains with error. */ } int MyApp::UnhandledExceptionHandler(LPEXCEPTION_POINTERS exceptionInfo) { // Perform logging, write crash dump, etc. // Actually no idea how to do this in WinRT yet.

    return EXCEPTION_EXECUTE_HANDLER; }

    For meaning of EXCEPTION_EXECUTE_HANDLER and more info on SEH, see following:

    https://msdn.microsoft.com/en-us/library/s58ftw19.aspx


    Wednesday, August 5, 2015 9:38 PM