Created
October 28, 2015 09:22
-
-
Save paveltimofeev/5ea76f70b59cd934704c to your computer and use it in GitHub Desktop.
Catching Game Try/Catch/Finally
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
/// <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