1

I have a SL OOB app (it only runs OOB) and was wondering about the ReportErrorToDOM code in the app.xaml.css:

From what I understand, HtmlPage wont work in OOB as there is no DOM/HTML? Is that why this code is wrapped in a TryCatch block? (this is the default for a new SL4 app).

To get my OOB app to display unhandled errors to the UI, should I judt replace the HTMLPage with a MessageBox.Show?

I can't find anything on Google about this, opinions appreciated...

  private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
    {
        try
        {
            string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
            errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");

            System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
        }
        catch (Exception)
        {
        }
    }
Rodney
  • 5,417
  • 7
  • 54
  • 98

2 Answers2

1

As an initial starting position yes you should replace the code with code that uses MessageBox.Show to display the error.

What is appropriate for a production quality release will depend on the type of application. Strictly speaking if your application has encountered an unhandled exception it would be in an indeterminate state so a message box and/or the replacing of the root visual might make sense.

If its a game then simply swallowing the error might even be appropriate or just noting it in some log.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Thanks for your advice Anthony. I'll probably log the error and show something basic in the MessageBox. – Rodney Dec 19 '10 at 21:21
0

Take a look at the Silverlight Navigation Application template in VS - it uses a ChildWindow to show errors, and this works OOB as well. You could just generate a dummy project from this template and copy/paste most of the code over to your app to get going quickly, then tweak the UI to suit your needs.

Austin Lamb
  • 3,116
  • 1
  • 22
  • 13