Skip to content

Instantly share code, notes, and snippets.

@paveltimofeev
Created October 28, 2015 09:22
Show Gist options
  • Save paveltimofeev/5ea76f70b59cd934704c to your computer and use it in GitHub Desktop.
Save paveltimofeev/5ea76f70b59cd934704c to your computer and use it in GitHub Desktop.
Catching Game Try/Catch/Finally
/// <summary>
/// Replace ??? with a number(s) of printing order
/// </summary>
class CatchingGame
{
public CatchingGame()
{
Console.WriteLine("1 - Catching Game");
Bob(new Action(Alice), "Alice" );
Bob(new Action(Mary), "Mary" );
}
private void Alice()
{
try
{
throw new Exception("Alice");
}
finally
{
Console.WriteLine("??? - Alice was thrown");
}
}
private void Mary()
{
try
{
throw new Exception("Mary");
}
finally
{
Console.WriteLine("??? - Jack throw Jane");
throw new Exception("Jane");
}
}
public void Bob(Action action, string name)
{
try
{
action.Invoke();
}
catch (Exception ex)
{
Console.WriteLine("??? - Bob catch " + ex.Message);
}
finally
{
Console.WriteLine("??? - Is Bob happy with " + name + "?");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment