Skip to content

Instantly share code, notes, and snippets.

@elmotec
Last active December 18, 2015 22:08
Show Gist options
  • Save elmotec/5851833 to your computer and use it in GitHub Desktop.
Save elmotec/5851833 to your computer and use it in GitHub Desktop.
How to change the message in an exception to add context information.
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