Skip to content

Instantly share code, notes, and snippets.

@cmd-not-found
Created April 14, 2021 01:45
Show Gist options
  • Select an option

  • Save cmd-not-found/8977c3a0172114940d1a03486f4c00f7 to your computer and use it in GitHub Desktop.

Select an option

Save cmd-not-found/8977c3a0172114940d1a03486f4c00f7 to your computer and use it in GitHub Desktop.
# 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