Thursday, February 12, 2009

Silverlight Error handling at user control level

When you are developing user control in Silverlight you might want to handle all errors for that user control at one place. For handling all errors at one place you have to subscribe to event
UnhandledException of the App class
Code
  public partial class Page : UserControl
{

public Page()

{

InitializeComponent();

App.Current.UnhandledException += new EventHandler(Current_UnhandledException);



}



void Current_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)

{

//handle exception here. like showing a message box

}



}


No comments: