Reputation: 40
I Have a class, that should not show any dialogs to final user. In case, that user passed wrong filepath, i tried to throw and exception and handle it in proper class. However, despite 'throw' instruction, Visual Studio shows Exception Dialog and breaks application after it occurs (Debuging mode). In Release mode application just crashes after giving wrong filepath. What am i doing wrong?
GuyManager.cs:
private IStorageFile latestGuyFile;
public IStorageFile LatestGuyFile { get { return latestGuyFile; } }
public string Path { get; set; }
public async void ReadGuyAsync()
{
if (String.IsNullOrWhiteSpace(Path))
return;
try
{
latestGuyFile = await StorageFile.GetFileFromPathAsync(Path);
}
catch (Exception ex)
{
Debug.WriteLine("Error occured: " +ex.Message);
Debug.WriteLine(ex.StackTrace);
throw;
}
MainPage.xml.cs:
private async void loadGuy_Click(object sender, RoutedEventArgs e)
{
try
{
guyManager.ReadGuyAsync();
}
catch (Exception ex)
{
MessageDialog dialog = new MessageDialog("Error" + ex.Message);
await dialog.ShowAsync();
}
}
Upvotes: 1
Views: 54
Reputation: 1613
I see a problem in your Click event handler. You define it as async, but you are not awaiting anything.
You should change the ReadGuyAsync method to return a Task instead of void, like this:
public async Task ReadGuyAsync()
and in the loadGuy_Click method, you should await it:
await guyManager.ReadGuyAync();
Upvotes: 1