Hi I’m calling some items from a web service and when they come back I create an interface tailored to the items returned inside of a seperate method. Now every time in a great while something goes wrong and I need to catch the exception and display a message to the user.
private void itemHelper_FeaturedItemsCalled(object sender, List<MyItem> _myItemList)
{
try
{
Dispatcher.BeginInvoke(() =>
{
if(_myItemList != 0)
CreateInterface(_myItemList);
});
}
catch
{
Dispatcher.BeginInvoke(() =>
{
LoadingScreen.Visibility = System.Windows.Visibility.Visible;
LoadingTextBlock.Text = "Unable to display items.";
BusyIndicator1.IsRunning = false;
}
}
}
Now I purposely threw an exception inside the method CreateInterface(). Now when this runs I get and unhandled exception. Why is that? I thought since the method was called inside of the try it would eventually get handled here?
Try putting the try catch inside the BeginInvoke. What is happening is that you are executing this code on a different thread so the exception is not caught by the differing thread.