码迷,mamicode.com
首页 > 编程语言 > 详细

【Python学习】详细异常信息

时间:2020-05-23 16:47:24      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:装饰器   ace   nes   info   python   line   col   form   back   

 

def robust(func):
    """
    异常追踪装饰器
    :param func:
    :return:
    """
    def add_robust(*args, **kwargs):
        try:
            previous_frame = inspect.currentframe().f_back
            caller_filename, caller_line_number, caller_function_name, caller_lines, caller_index = inspect.getframeinfo(
                previous_frame)
            LOG_DEBUG(caller_filename: {}, caller_line_number: {}, caller_function_name: {}.format(caller_filename,
                                                                                                 caller_line_number,
                                                                                                 caller_function_name))
            return func(*args, **kwargs)
        except Exception:
            LOG_ERROR(Error execute func:{}.format(func.__name__))
            traceback.print_exc()
    return add_robust
try:
    i = int(a)
except Exception, e:
    print str(Exception):\t, str(Exception)
    print str(e):\t\t, str(e)
    print repr(e):\t, repr(e)
    print e.message:\t, e.message
    print traceback.print_exc():; traceback.print_exc()
    print traceback.format_exc():\n%s % traceback.format_exc()

 

【Python学习】详细异常信息

标签:装饰器   ace   nes   info   python   line   col   form   back   

原文地址:https://www.cnblogs.com/gtea/p/12942783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!