Up Tour of DevForce Silverlight
DevForce 2010 Resource Center » DevForce overview » Tour of DevForce Silverlight » Tour of DevForce Silverlight - Part 5

Tour of DevForce Silverlight - Part 5

Last modified on August 15, 2012 17:22

Part 5: Coping with Trouble - In Part 5 of this series we'll work with the application from Part 4 to add error handling.


Tip  For best results, code along with the step-by-step video

The DebugLog

When stuff happens one of the first things you should do is look at the DevForce DebugLog.  DevForce always generates tracing messages as it runs, and by default writes those messages on the EntityServer to a file named DebugLog.xml.  When a problem occurs in your application, the messages in the log can often help to diagnose the problem.

As shown during the video, if we introduce an error (here we modified the database connection string) a message will be recorded in the log file indicating the problem:

dberror.JPG

Add error handling

Every application should have error handling, and we've been remiss in not adding it earlier.  When using asynchronous queries and saves we can't add a try/catch to handle the problem, as we would with synchronous operations.  Instead the exception is returned when the asynchronous operation completes in the Error property.  

C#
query.ExecuteAsync(
  op => {
   if (op.HasError) {
     throw new InvalidOperationException("Query failed: " + op.Error);
    }
    op.Results.ForEach(Employees.Add);
    CurrentEmployee = Employees.FirstOrDefault();
  });
VB
query.ExecuteAsync(Sub(op)
 If op.HasError Then
   Throw New InvalidOperationException("Query failed: " & op.Error)
 End If
  op.Results.ForEach(Employees.Add)
  CurrentEmployee = Employees.FirstOrDefault()
End Sub)  

To keep your application from terminating due to the exception you can call op.MarkErrorAsHandled().

As of DevForce 6.0.5 all unhandled exceptions from asynchronous operations are re-thrown.  This was not shown in the video, as it was recorded with an earlier version of DevForce.

Learn More

Here are some links for more detail on what we've covered here, and additional information we hope you find useful.

Prerequisites

The user interface for the application built during this tour uses a DataForm component supplied by the Silverlight 4 Toolkit (different from the Silverlight 4 Tools!). You can download the Toolkit here:

http://silverlight.codeplex.com/

To work with this application, as all DevForce 2010 Silverlight applications, you will need Visual Studio 2010, the Silverlight 4 runtime (SilverlightTools.exe), and DevForce installed.

Created by DevForce on May 11, 2011 17:34

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade