dochelpers.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:niceman 作者: ReproNim 项目源码 文件源码
def exc_str(exc=None, limit=None):
    """Enhanced str for exceptions.  Should include original location

    Parameters
    ----------
    Exception to
    """
    out = str(exc)
    if limit is None:
        # TODO: config logging.exceptions.traceback_levels = 1
        limit = int(os.environ.get('NICEMAN_EXC_STR_TBLIMIT', '1'))
    try:
        exctype, value, tb = sys.exc_info()
        if not exc:
            exc = value
            out = str(exc)
        # verify that it seems to be the exception we were passed
        #assert(isinstance(exc, exctype))
        if exc:
            assert(exc is value)
        entries = traceback.extract_tb(tb)
        if entries:
            out += " [%s]" % (','.join(['%s:%s:%d' % (os.path.basename(x[0]), x[2], x[1]) for x in entries[-limit:]]))
    except:
        return out  # To the best of our abilities
    finally:
        # As the bible teaches us:
        # https://docs.python.org/2/library/sys.html#sys.exc_info
        del tb
    return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号