Created
February 27, 2019 14:32
-
-
Save felipeslongo/c1c6df5d95a9b0eceeec4c11ba757bb9 to your computer and use it in GitHub Desktop.
How exception works
This file contains 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
static void async Main(string[] args) | |
{ | |
try | |
{ | |
await ThrowExceptionAfterAsync(); | |
} | |
catch(Exception e) | |
{ | |
//Gonna catch SHU | |
Console.WrileLine(e.Message);//SHU | |
} | |
try | |
{ | |
ThrowExceptionAfterAsync();//Exceptions thrown will be swallowed | |
} | |
catch(Exception e) | |
{ | |
//Never gonna hit. | |
Console.WrileLine(e.Message); | |
} | |
try | |
{ | |
ThrowExceptionBeforeAsync(); | |
} | |
catch(Exception e) | |
{ | |
//Gonna catch SHU | |
Console.WrileLine(e.Message); | |
} | |
} | |
public static async Task ThrowExceptionAfterAsync() | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(5)); | |
throw new Exception("SHU"); | |
} | |
public static async Task ThrowExceptionBeforeAsync() | |
{ | |
throw new Exception("SHU"); | |
await Task.Delay(TimeSpan.FromSeconds(5)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment