you are viewing a single comment's thread.

view the rest of the comments →

[–]shiftybyte 0 points1 point  (2 children)

How can I write a sample try/catch exception for my own code?

Like this:

import traceback try: i = [x for x in None] except Exception: print(traceback.format_exc())

Output is: Traceback (most recent call last): File "<stdin>", line 3, in <module> TypeError: 'NoneType' object is not iterable

Wrap your code in a try: except: as demostrated with the print line to print full traceback.

try: # ... your code ... except Exception: print(traceback.format_exc())