Guest User

Untitled

a guest
Jan 15th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. private static async Task Main(string[] args)
  2. {
  3. try
  4. {
  5. await Exception();
  6. }
  7. catch(Exception)
  8. {
  9.  
  10. }
  11. }
  12.  
  13. public static async Task Exception()
  14. {
  15. var longTask = LongTask();
  16. var shortTask = Task.Delay(3000);
  17.  
  18. if (await Task.WhenAny(longTask, shortTask) == shortTask)
  19. {
  20. throw new ShortException();
  21. }
  22. }
  23.  
  24. public static async Task LongTask()
  25. {
  26. await Task.Delay(6000);
  27. throw new LongException();
  28. }
  29.  
  30. public class ShortException : Exception {}
  31. public class LongException : Exception {}
Advertisement
Add Comment
Please, Sign In to add comment