Last active
December 18, 2015 22:08
-
-
Save elmotec/5851833 to your computer and use it in GitHub Desktop.
How to change the message in an exception to add context information.
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
def process(val): | |
try: | |
do_something(val) | |
except Exception as ex: | |
msg = '{}: {}'.format(val, ex.args[0]) if ex.args else str(val) | |
ex.args = (msg,) + ex.args[1:] | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://stackoverflow.com/questions/17677680/how-can-i-add-context-to-an-exception-in-python