Last active
June 12, 2017 16:53
-
-
Save jmrr/a7dfb821916185fbba2e484807a89dc4 to your computer and use it in GitHub Desktop.
Catching exception the proper way in Python: finding out the exception name
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
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