CATCHING AND DEBUGGING ERRORS in Microsoft Word

Encoder QR Code JIS X 0510 in Microsoft Word CATCHING AND DEBUGGING ERRORS

CHAPTER 4 CATCHING AND DEBUGGING ERRORS
Printing QR Code JIS X 0510 In None
Using Barcode generation for Office Word Control to generate, create QR Code JIS X 0510 image in Office Word applications.
www.OnBarcode.com
Generate GS1 128 In None
Using Barcode encoder for Word Control to generate, create UCC - 12 image in Office Word applications.
www.OnBarcode.com
Figure 4 3. Query object value in Immediate Window
Making EAN-13 Supplement 5 In None
Using Barcode generation for Office Word Control to generate, create EAN-13 Supplement 5 image in Word applications.
www.OnBarcode.com
Barcode Drawer In None
Using Barcode creation for Microsoft Word Control to generate, create Barcode image in Word applications.
www.OnBarcode.com
Catching an Unhandled Exception in RootFrame_NavigationFailed or Application_UnhandledException
Generate Data Matrix In None
Using Barcode creator for Word Control to generate, create ECC200 image in Word applications.
www.OnBarcode.com
USS Code 39 Printer In None
Using Barcode drawer for Microsoft Word Control to generate, create USS Code 39 image in Office Word applications.
www.OnBarcode.com
Unhandled exceptions in a Windows Phone application will be caught by one of two main methods: RootFrame_NavigationFailed, and Application_UnhandledException. RootFrame_NavigationFailed catches unhandled exceptions thrown while a page is being loaded; Application_UnhandledException catches exceptions thrown in all other cases. 1. Press F5 to continue debugging from the breakpoint in the previous section.
Encode PDF-417 2d Barcode In None
Using Barcode creator for Word Control to generate, create PDF-417 2d barcode image in Office Word applications.
www.OnBarcode.com
Painting Code 2/5 In None
Using Barcode printer for Word Control to generate, create Code 2/5 image in Microsoft Word applications.
www.OnBarcode.com
The debugger will next break inside RootFrame_NavigationFailed in App.xaml.cs as shown in Figure 4 4. Notice that in App.xaml.cs you will find various Windows Phone application related events such as Application_Launching, Application_Activated, Application_Deactivated, Application_Closing, RootFrame_NavigationFailed, and Application_UnhandledException. As far as exceptions are concerned, only two events will be of interest. RootFrame_NavigationFailed captures unhandled exceptions when the Windows Phone page fails to load. In ErrorHandlingDemo, unhandled exceptions occur when MainPage tries to load and throws ArgumentOutOfException.
Create QR In None
Using Barcode generator for Font Control to generate, create Denso QR Bar Code image in Font applications.
www.OnBarcode.com
Decoding QR-Code In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
CHAPTER 4 CATCHING AND DEBUGGING ERRORS
Drawing Barcode In Visual Studio .NET
Using Barcode encoder for .NET framework Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
Barcode Creation In .NET
Using Barcode creation for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
Figure 4 4. Breakpoint at RootFrame_NavigationFailed 2. With your mouse, hover over NavigationFailedEventArgs e and you will be able to drill into the object value and see the e.Uri that contains the page that caused the error during the load, as shown in Figure 4 5.
Barcode Maker In Java
Using Barcode generation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Data Matrix ECC200 Creation In Visual Studio .NET
Using Barcode generator for ASP.NET Control to generate, create DataMatrix image in ASP.NET applications.
www.OnBarcode.com
Figure 4 5. NavigationFailedEventArgs.Uri
Print 1D Barcode In VB.NET
Using Barcode creation for Visual Studio .NET Control to generate, create 1D image in Visual Studio .NET applications.
www.OnBarcode.com
Recognize Code39 In Visual C#.NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
CHAPTER 4 CATCHING AND DEBUGGING ERRORS
Printing USS Code 39 In Java
Using Barcode creator for Android Control to generate, create Code 39 Extended image in Android applications.
www.OnBarcode.com
Barcode Scanner In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Press F5 to continue debugging, and you will notice that code execution next breaks in the Application_UnhandledException method. All exceptions that are not handled specifically by a try-catch-finally block will ultimately end up in this method.
ANSI/AIM Code 128 Decoder In C#.NET
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Encode Barcode In .NET Framework
Using Barcode generation for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Handling an Exception RootFrame_NavigationFailed
When an exception is thrown in the MainPage of an application, the exception will be caught by the RootFrame_NavigationFailed method, and this is where you want to handle it in order to stop the exception from bubbling up to the Application_UnhandledException method. In ErrorHandlingDemo, replace the RootFrame_NavigationFailed method with following code. Notice the use of MessageBox in the code to display the proper error with stack trace and set e.Handled to true, which will stop the breakpoint to move to the Application_UnhandledException method. // Code to execute if a navigation fails private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) { // A navigation has failed; break into the debugger System.Diagnostics.Debugger.Break(); } MessageBox.Show( string.Format("Page {0} failed to load because of with error: {1}", e.Uri.ToString(), e.Exception.StackTrace)); e.Handled = true; }
Fixing the Error in the Code
In the previous section, you added a MessageBox display in case any other page fails to load, and in the following steps, you will be fixing the actual cause of the exception in MainPage. But first, let s fix the error in MainPage.xaml.cs. Fix the error in MainPage.xaml.cs by replacing txtDeviceName.Text = DeviceExtendedProperties.GetValue("DName").ToString() with txtDeviceName.Text = DeviceExtendedProperties.GetValue("DeviceName").ToString().
Debugging a Web Service Exception
ErrorHandlingDemo contains the CalculatorService web service project, where the service will be hosted locally and consumed by the demo application. The code is written so that the application will throw the exceptions that you will be fixing.
CHAPTER 4 CATCHING AND DEBUGGING ERRORS
Catching a Web Service Exception
You will be stepping through the breakpoints in order to understand the behavior of the thrown exception. Before you begin, we need to make sure that both the Windows Phone project and the web service project start simultaneously when you Press F5. 1. 2. 3. Right-click the ErrorHandlingDemo solution in Solution Explorer and choose the property. The solution property page Window shown in Figure 4 6 will display. Select the Multiple startup projects option, and CalculatorService and ErrorHandlingDemo projects Actions are set to Start. Also put two breakpoints in MainPage.xaml.cs, as shown in Figure 4 6, at the line txtAnswer.Text = e.Result.ToString() and _svc.AddAsync(txtX.Text, txtY.Text).
Figure 4 6. Breaking point to debug CalculatorService web service 4. Press F5 and you will see the application show in Figure 4 1 in the emulator, and you will notice the WCF Test Client starts as well, as shown in Figure 4 7. The WCF Test Client will host the CalculatorService, allowing you to step into the web service call.
CHAPTER 4 CATCHING AND DEBUGGING ERRORS
Figure 4 7. WCF test client 5. From the emulator, press the Call Calculator Service button.
Notice that the Visual Studio catches InvalidCastException thrown from the CalculatorService project, as shown in Figure 4 8.
Copyright © OnBarcode.com . All rights reserved.