def db():
    return False

def index():
    try:
        result = db()
        if not result:
            raise Exception('数据库处理错误')    #主动触发异常
    except Exception as e:
        str_error = str(e)
        print(str_error)

index()

输出:

数据库处理错误

posted on 2021-12-12 19:27  csy113  阅读(144)  评论(0编辑  收藏  举报