2020年10月30日 星期五

例外處理 try except 顯示完成的Exception訊息-When I catch an exception, how do I get the type, file, and line number?

Code

'''
System version : Windows 10  64-bit  
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)   
'''

import traceback

try:
    print(a)

except Exception as e:
    print('simple message:')
    print('repr(e):\n',repr(e))
    print('-'*45)
    print('detail message:')
    print('traceback.format_exc():\n',traceback.format_exc())

Result