• 【Python学习】详细异常信息


    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):	', str(Exception)
        print 'str(e):		', str(e)
        print 'repr(e):	', repr(e)
        print 'e.message:	', e.message
        print 'traceback.print_exc():'; traceback.print_exc()
        print 'traceback.format_exc():
    %s' % traceback.format_exc()
    作者:gtea 博客地址:https://www.cnblogs.com/gtea
  • 相关阅读:
    单例设计模式
    使用JfreeChart生成统计图
    session的生命周期
    json
    struts2 ognl标签使用
    集合小结
    多线程
    内部类和匿名内部类
    模版方法设计模式
    mac中yeoman构建你的项目
  • 原文地址:https://www.cnblogs.com/gtea/p/12942783.html
Copyright © 2020-2023  润新知