问题
I observe very strange exception handling behavior in any Windows 8.1 (WinRT) application. I've created default project "Blank App (Windows 8.1)", declared MyException exception class and throw it in button's click event handler. I have submitted to Application.UnhandledException event and trying to get the type of received exception. Sometimes it is my exception, sometimes it is common System.Exception. Sometimes debugger shows it is common Exception but application works as it would be MyException: Question is "How to make a WinRT application to work the same way as .NET application in context of exceptions, and as it is declared by winRT documentation? I want to receive exception object that I have thrown".
回答1:
I should save UnhandledExceptionEventArgs.Exception value to a variable before reading any properties of UnhandledExceptionEventArgs class. After that you can access any information (like stack trace) at any moment by reading your variable value(not UnhandledExceptionEventArgs.Exception value). That behavior seems to be an issue so I reported it: https://connect.microsoft.com/VisualStudio/feedback/details/3134547/windows-rt-8-1-unhandledexceptioneventargs-issue
来源:https://stackoverflow.com/questions/44100603/improper-winrt-exception-behavior