打印当前.py文件错误行:

import sys
try:
        a = [1,2]
        print a[3]
except:
        s=sys.exc_info()
        print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)

 

打印execfile的打印错误行:

try:
        execfile("tprint.py")
except Exception, info:
        #print info[1]
        print "Error '%s' happened on line %d" % (info[0], info[1][1])

 

 

利用反射机制,调用函数,打印被调用方的错误行及错误信息        
try:
                callfunc.callfunc(myklass,strmethod,params)
        except :
                print '=== STEP ERROR INFO START'
                import traceback
                traceback.print_exc()
                print '=== STEP ERROR INFO END'

相关文章:

  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-29
  • 2021-06-24
  • 2022-02-14
  • 2021-10-07
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案