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()
输出:
数据库处理错误