Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Last active March 27, 2020 17:22
Show Gist options
  • Save jeremysimmons/067a4d181c4e6f515b4250d10d7fe53e to your computer and use it in GitHub Desktop.
Save jeremysimmons/067a4d181c4e6f515b4250d10d7fe53e to your computer and use it in GitHub Desktop.
c# throwing exceptions
// 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