方式一:

try:
  do_something
except Exception as e:
  print('[INFO]exception info: ', e.args)

方式二:

import traceback 

try:
  do_something
except:
  print('[INFO]exception info: ', traceback.format_exc())

#traceback.print_exc() 直接打印异常
#traceback.print_exc(file=open(‘error.txt','a+')) 写入文件
#traceback.format_exc() 返回字符串
Last modification:May 25th, 2021 at 11:26 am