tomasslavicek

Try catch from async void

Feb 6th, 2020
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.29 KB | None | 0 0
  1. private async void OnClick()
  2. {
  3.     try
  4.     {
  5.         await Download();
  6.     }
  7.     catch (Exception e)
  8.     {
  9.         Console.WriteLine(e);
  10.     }
  11. }
  12.  
  13. private async Task Download()
  14. {
  15.     Console.Write("Download started");
  16.     await Task.Delay(1000);
  17.  
  18.     throw new Exception("Error");
  19. }
Advertisement
Add Comment
Please, Sign In to add comment