locked
How to protect against crashes?

    Question

  • I wonder why SetUnhandledExceptionFilter is not allowed in WinRT apps? How are we supposed to handle crashes in 3rd party libraries? What if a 3rd party library accesses non-readable memory inside a WinRT process (WinJS in that case, wwahost.exe)?

    Is there any way to protect the app against that? I wanted to implement my own exception filter using SetUnhandledExceptionFilter and send a Platform:Exception back to the app from my WinRT component. What alternative ways do we have here?

    Wednesday, May 02, 2012 12:41 PM

All replies

  • SetUnhandledExceptionFilter is not a protection against access violation, it merely gives you a chance to debug or log the error. You should crash if there is an unhanded exception,  it is much better to not save anything than save corrupted user data. You should not swallow the exception and pretend nothing happened.

    Use the libraries in a surrogate process to protect your own process from crashing.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


    Wednesday, May 02, 2012 2:37 PM
  • I was not about to swallow the exception. I was about to throw a Platform exception instead. But anyway, COM Surrogate looks good. Can we use it in Metro apps and how?
    Wednesday, May 02, 2012 2:41 PM
  • Depends on what your third-party dlls do. If they are doing something that cannot be completed in 5 seconds, then they need to be hosted in a desktop app.

    Communication between metro apps in the same package is OK. But inter-process communication is not something suggested to use in between metro apps and desktop apps. Anyway, you can use WCF to communicate to a service hosted in a windows service. This may not be the best design (e.g. batter draining), however.

    You create a surrogate process by creating a new process, loading the COM server (through registry-free activation if in metro apps as registry may not be available), then design an inter-process contract to relay COM calls.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP



    Wednesday, May 02, 2012 5:12 PM
  • The 3rd party is a C-Library. It's unstable sometimes and I need to protect my metro app against random crashes of this library.

    There is no way in metro apps to create a new process according to the MSDN docs.

    Communication between metro apps is also not an option here. The code lies in a WinRT component DLL, which is loaded into the same process as the metro app using it.

    Thursday, May 03, 2012 8:40 AM
  • there is a sample in the MSDN code gallary set called "Association Launching Sample". You can declare a file type or protocol registration in your metro style app's manifest , create a command file or url, then launch the file or url.

    Whether the code is in a WinRT component does not matter to communication between metro apps, as the surrogate process is a metro app, it can load WinRT components as well.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    Thursday, May 03, 2012 1:39 PM