Last active
April 2, 2020 06:52
-
-
Save usausa/f6be9a2d31bca60f3ad778e6175b0509 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static async Task Main(string[] args) | |
| { | |
| try | |
| { | |
| await Task.Run(async () => await LongProcessAsync()); | |
| } | |
| catch (Exception e) | |
| { | |
| // Can catch | |
| Console.WriteLine(e); | |
| } | |
| try | |
| { | |
| await Task.Run(LongProcessAsync); | |
| } | |
| catch (Exception e) | |
| { | |
| // Can't catch | |
| Console.WriteLine(e); | |
| } | |
| } | |
| private static async ValueTask LongProcessAsync() | |
| { | |
| // Context switch | |
| await Task.Delay(100); | |
| throw new Exception("Otanko🍆"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment