Created
February 20, 2020 21:09
-
-
Save matthewdeanmartin/44b310b88eeb69c0ab0b312e48753126 to your computer and use it in GitHub Desktop.
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
from typing import Callable | |
def try_catch(to_try:Callable, to_catch:Callable, exception_type:Exception, to_finally:Callable): | |
try: | |
to_try() | |
except exception_type as exception: | |
to_catch(exception) | |
finally: | |
to_finally() | |
def example(): | |
message_via_closure = "oops" | |
def try_it(): | |
raise TypeError(message_via_closure) | |
def catch_it(exception:Exception): | |
print(message_via_closure + " 2") | |
print(str(exception) + " is the exception message") | |
def finally_it(): | |
print(message_via_closure + " 3") | |
print("closing connection") | |
try_catch(try_it, catch_it, TypeError, finally_it) | |
example() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment