Last active
March 27, 2020 17:22
-
-
Save jeremysimmons/067a4d181c4e6f515b4250d10d7fe53e to your computer and use it in GitHub Desktop.
c# throwing exceptions
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
// For example, in .NET if an exception is thrown/re-thrown from the catch block, then the finally block will not execute. | |
try | |
{ | |
try | |
{ | |
Console.WriteLine("try"); | |
throw new Exception("intentional"); | |
Console.WriteLine("will not print"); | |
} | |
catch (Exception exception) | |
{ | |
Console.WriteLine("catch"); | |
Console.WriteLine(exception.Message); | |
throw exception; | |
} | |
finally | |
{ | |
Console.WriteLine("finally"); | |
} | |
} | |
catch | |
{ | |
Console.WriteLine("caught an exception"); | |
} | |
/* | |
Prints: | |
try | |
catch | |
intentional | |
finally | |
caught an exception | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment