Created
October 26, 2018 15:23
-
-
Save hughdbrown/2260087e58577935e1b441d2064fbb6b to your computer and use it in GitHub Desktop.
Decorator that can track usage through exceptions
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
def a(throw_please=False): | |
_ret = None | |
_exc = None | |
try: | |
print("try") | |
if throw_please: | |
b = [] | |
b[1] = 3 | |
_ret = 4 | |
except Exception as exc: | |
print("except") | |
_exc = exc | |
raise | |
else: | |
print("else") | |
return _ret | |
finally: | |
print("finally fn_name: |{2}| ret: |{0}| exc: |{1}|".format(_ret, _exc, a.func_name)) | |
print("a() = {0}".format(a(False))) | |
print("a() = {0}".format(a(True))) | |
""" | |
>>> print("a() = {0}".format(a(False))) | |
try | |
else | |
finally fn_name: |a| ret: |4| exc: |None| | |
a() = 4 | |
>>> print("a() = {0}".format(a(True))) | |
try | |
except | |
finally fn_name: |a| ret: |None| exc: |list assignment index out of range| | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "<stdin>", line 8, in a | |
IndexError: list assignment index out of range | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment