Created
April 14, 2021 01:45
-
-
Save cmd-not-found/8977c3a0172114940d1a03486f4c00f7 to your computer and use it in GitHub Desktop.
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
| # This is an example of capturing the traceback of an exception | |
| # It demonstrates the data available, including the type of Exeption subclass, the value, and the tracebook object. | |
| try: | |
| print(test[2]) | |
| except: | |
| tb = sys.exc_info() | |
| for i in tb: | |
| print(i) | |
| # tb is a list of len==3 | |
| # tb[0] type ex. <class 'TypeError'> | |
| # tb[1] value ex. TypeError("'set' object is not subscriptable") | |
| # tb[2] traceback ex. <traceback object at 0x1079cd100> | |
| # REF: https://docs.python.org/3/library/sys.html#sys.exc_info | |
| # REF for tb[2]: https://docs.python.org/3/reference/datamodel.html#traceback-objects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment