import traceback,sys
import requests
try :
requests.get('dsdsd') ##故意让他出错
except Exception,e:
print '\033[1;35;40m%s\033[0m'%str(e)
#traceback.print_exc()
print '\033[4;32;0m%s\033[0m'%traceback.format_exc()
info = sys.exc_info()
print '\033[7;32;0m%s : %s \033[0m'%(info[0],info[1])
#sys.exit(666)
print 'hello'
exception 能看到错误提示
traceback能看到具体的错误在哪一行,当try里面包含了上百行代码,包括功能现金的代码,如果只是用exception打印,可能不知道是哪出错了,而且不好调试定位,taraceback就十分好了。
sys.exc_info能看到错误类型和错误提示。