{"id":1383,"date":"2013-07-01T10:00:00","date_gmt":"2013-07-01T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2013\/07\/01\/improved-exception-reporting-for-c-windows-store-apps-in-visual-studio-2013\/"},"modified":"2021-09-29T13:18:19","modified_gmt":"2021-09-29T13:18:19","slug":"improved-exception-reporting-for-c-windows-store-apps-in-visual-studio-2013","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/improved-exception-reporting-for-c-windows-store-apps-in-visual-studio-2013\/","title":{"rendered":"Improved exception reporting for C++ Windows Store Apps in Visual Studio 2013"},"content":{"rendered":"<p>Windows 8.1 and Visual Studio 2013 come with improvements for exception reporting in the platform and the debugger which will make it easier for native Windows Store App developers to diagnose errors in their applications. In this post, I&rsquo;ll discuss a few of those improvements that are available in Visual Studio 2013 and show the differences in the debugging experience between Visual Studio 2012 and Visual Studio 2013.<\/p>\n<p>The sample project that contains the code snippets in this post can be downloaded from <a title=\"here\" href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/ExceptionSample.zip\">here<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h2>Captured Stacks for Windows Runtime Exceptions<\/h2>\n<p>Windows 8.1 adds support for capturing stack traces for exceptions as they are reported in Windows Runtime components. The debugger in Visual Studio 2013 can display those captured stack traces whenever they are available on exception objects that are derived from Platform::Exception.<\/p>\n<p>To see this in action, start debugging <a title=\"the sample application in this post\" href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/ExceptionSample.zip\">the sample application in this post<\/a> in Visual Studio 2013, put a breakpoint in the catch block below and then click on &lsquo;Throw Handled&rsquo; button in the main application page. It will execute the event handler code below which simply catches an exception that is thrown inside the ThrowDataReaderError method.<\/p>\n<p><span style=\"font-family: 'courier new', courier;font-size: small\">void ExceptionSample::MainPage::ThrowDataReaderError()<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;font-size: small\"> {<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; DataReader^ dataReader = ref new DataReader(nullptr);<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; dataReader-&gt;LoadAsync(100);<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> }<\/span><\/p>\n<p><span style=\"font-family: 'courier new', courier;font-size: small\">void ExceptionSample::MainPage::btnThrowHandled_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\">{<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; try<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; {<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ThrowDataReaderError();<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; }<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp; &nbsp; catch (Platform::Exception^ e)<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp; &nbsp; {<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputTextBlock-&gt;Text = e-&gt;Message;<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> &nbsp;&nbsp;&nbsp; }<\/span><br \/><span style=\"font-family: 'courier new', courier;font-size: small\"> }<\/span><\/p>\n<p>The COM exception raised inside LoadAsync method causes the execution to break into the debugger with the exception dialog showing its details. The Visual Studio 2012 version of the dialog shows only the WinRT error information for this exception:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2013\/07\/7608.6_29_2013_3_48_PM_37.png\">