Skip to content

Instantly share code, notes, and snippets.

@jmrr
Last active June 12, 2017 16:53
Show Gist options
  • Save jmrr/a7dfb821916185fbba2e484807a89dc4 to your computer and use it in GitHub Desktop.
Save jmrr/a7dfb821916185fbba2e484807a89dc4 to your computer and use it in GitHub Desktop.
Catching exception the proper way in Python: finding out the exception name
try:
# Code here
except Exception as ex:
template = "An exception of type {0} occured. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print(message)
# Here you can do post-mortem analysis, present GUI error message, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment