Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a global exception handler in Windows store apps?

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();
    }
}
like image 648
B. Clay Shannon-B. Crow Raven Avatar asked Nov 29 '12 23:11

B. Clay Shannon-B. Crow Raven


People also ask

How many global exception handlers are there?

Only one Global Exception Handler can be set per automation project. By default, the template retries the exception 3 times before aborting the execution. This default behavior can be changed from inside the template.

What is Windows exception handler?

The operating system uses structured exception handling to signal certain kinds of errors. A routine called by a driver can raise an exception that the driver must handle. The system traps the following general kinds of exceptions: Hardware-defined faults or traps, such as, Access violations (see below)

How do I create a global exception handler?

Adding a Global Exception Handler The New Global Handler window opens. Type in a Name for the handler and save it in the project path. Click Create, a Global Exception Handler is added to the automation project.

What is global exception handler?

Also, we identified that the global exception handler is a part of the Thread class and it handles the uncaught runtime exceptions. Then, we saw a sample program that throws a runtime exception and handles it using a global exception handler. The example codes for this article can be found over on GitHub.


1 Answers

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.

like image 193
Jim O'Neil Avatar answered Oct 04 '22 19:10

Jim O'Neil