try: something here except: print 'the whatever error occurred.'
How can I print the error/exception in my
For Python 2.6 and later and Python 3.x:
except Exception as e: print(e)
For Python 2.5 and earlier, use:
except Exception,e: print str(e)
import traceback try: 1/0 except Exception: traceback.print_exc()
Traceback (most recent call last): File "C:\scripts\divide_by_zero.py", line 4, in <module> 1/0 ZeroDivisionError: division by zero