17

For unhandled exceptions, at least, I'd like to be able to catch the details and write them out to a file for potential subsequent "debugging forensics." There is no "OnTerminating" event in Windows store apps; is there a suitable place/way to accomplish such?

UPDATE

See my comment below. Here is an addition that won't fit below:

Even when removing the xaml snippet, I still get that err msg, and even after Cleaning and Rebuilding...??? 2-clicking the err msg just takes me to the top of App.xaml, the entirety of which is now:

<Application
    x:Class="SpaceOverlays.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SpaceOverlays">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <!-- 
                    Styles that define common aspects of the platform look and feel
                    Required by Visual Studio project and item templates
                 -->
                <ResourceDictionary Source="Common/StandardStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
    </Application.Resources>

UPDATE 2

After closing App.xaml and rebuilding, all is well...??? Oh, well - all's well that ends well, I guess.

UPDATE 3

It's interesting that Windows Phone apps App.xaml.cs have this handler by default:

    // Global handler for uncaught exceptions.
    UnhandledException += Application_UnhandledException;

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
    if (Debugger.IsAttached)
    {
        // An unhandled exception has occurred; break into the debugger
        Debugger.Break();
    }
}
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

1 Answers1

8

For HTML5/JavaScript apps you have the onerror event as your last chance to capture info.

For XAML-based apps, you can use UnhandledException; however, that only captures exceptions that come up through the XAML (UI) framework and you don't always get a lot of information about what the root cause is, even in InnerException.

Update for Windows 8.1: UnhandledException also will capture exceptions that are created by an async void method. In Windows 8, such exceptions would just crash the app. LunarFrog has a good discussion of this on their website.

Xy Ziemba
  • 388
  • 2
  • 7
Jim O'Neil
  • 23,344
  • 7
  • 42
  • 67
  • I checked out that "Unhandled Exception" link. Where do I add that xaml snippet? If I put it in App.xaml, like so: ...I get the compile-time error, "Cannot add content to an object of type 'application'" Update added above diesbzg. – B. Clay Shannon-B. Crow Raven Dec 03 '12 at 00:04
  • 2
    add the exception in code to the App() constructor in App.xaml.cs: this.UnhandledException += – Jim O'Neil Dec 03 '12 at 00:52