当前位置:首页>python>第08篇|Python 异常处理:写出不会崩溃的代码

第08篇|Python 异常处理:写出不会崩溃的代码

  • 2026-03-21 01:27:07
第08篇|Python 异常处理:写出不会崩溃的代码

这篇文章带你系统掌握 Python 异常处理——try-except-finally、常见异常类型速查、自定义异常,以及把第 07 篇的 JSON 操作升级为生产级别的健壮代码。


前言

写代码最怕什么?程序在用户手上崩溃。

前端开发者对 try-catch 一定不陌生——网络请求失败、JSON 解析出错、DOM 元素不存在……这些都需要异常处理来兜底。

Python 里的异常处理和 JS 高度相似,但有一些重要的扩展能力:比 JS 更精细的异常分类、else 子句、自定义异常类。

这篇文章覆盖:

  • try-except-finally 基本用法(对比 JS try-catch-finally)
  • 常见内置异常类型速查
  • 主动抛出异常:raise
  • 自定义异常类
  • 实战:给第 07 篇的 JSON 文件操作加上完整异常处理

一、为什么需要异常处理?

先看一个没有异常处理的代码:

import jsondef read_config(filepath):    with open(filepath, "r") as f:        return json.load(f)config = read_config("config.json")print(config["database"]["host"])

当任何一步出问题时,程序直接崩溃并抛出错误信息——文件不存在、JSON 格式错误、键不存在……用户看到的是一堆红色报错,体验极差。

加上异常处理后,程序可以优雅地处理这些情况,给出友好提示,甚至自动恢复。


二、基本语法:try-except

2.1 最简单的用法

try:    result = 10 / 0          # 这行会抛出 ZeroDivisionError    print("不会执行到这里")except ZeroDivisionError:    print("❌ 除数不能为零")print("程序继续运行")

对比 JS:

try {  const result = riskyOperation()} catch (error) {  console.error("出错了:", error.message)}

核心区别:

  • Python 的 except 可以指定异常类型(精准捕获)
  • JS 的 catch 捕获所有异常,需要在内部判断类型

2.2 捕获多种异常

def parse_number(text):    try:        number = int(text)        result = 100 / number        return result    except ValueError:        print(f"❌ '{text}' 不是有效的数字")    except ZeroDivisionError:        print("❌ 不能除以零")    except Exception as e:        # 兜底:捕获所有其他异常        print(f"❌ 未知错误:{e}")parse_number("abc")   # 触发 ValueErrorparse_number("0")     # 触发 ZeroDivisionErrorparse_number("5")     # 正常运行,返回 20.0
# 也可以用元组一次捕获多种异常try:    ...except (ValueError, TypeError) as e:    print(f"输入类型错误:{e}")

2.3 获取异常信息

try:    with open("不存在的文件.txt") as f:        content = f.read()except FileNotFoundError as e:    print(f"错误类型:{type(e).__name__}")  # FileNotFoundError    print(f"错误信息:{e}")                  # [Errno 2] No such file or directory    print(f"错误码:{e.errno}")              # 2

三、完整结构:try-except-else-finally

Python 的异常处理有四个子句,比 JS 多了一个 else

try:    # 尝试执行的代码    result = int("42")except ValueError as e:    # 只有 try 块发生异常时执行    print(f"转换失败:{e}")else:    # 只有 try 块没有异常时执行(成功时的逻辑)    print(f"转换成功:{result}")finally:    # 无论是否异常,总会执行(用于清理资源)    print("执行结束")

else 的用途: 将"成功时的逻辑"和"主要代码"分开,代码结构更清晰。

# 实际场景:文件操作try:    with open("data.json", "r") as f:        data = json.load(f)except FileNotFoundError:    print("配置文件不存在,使用默认配置")    data = {}except json.JSONDecodeError:    print("配置文件格式错误")    data = {}else:    print(f"✅ 成功读取 {len(data)} 个配置项")finally:    print("配置加载流程结束")

对比 JS:

try {  const data = JSON.parse(text)  console.log("✅ 解析成功")  // else 的功能在 try 里实现} catch (e) {  console.error("解析失败", e)} finally {  console.log("结束")}

四、常见内置异常速查

异常类型
触发条件
示例
ValueError
值的类型对但内容不合法
int("abc")
TypeError
类型不匹配
"1" + 1
KeyError
字典键不存在
d["不存在的键"]
IndexError
列表下标越界
lst[100]
FileNotFoundError
文件不存在
open("不存在.txt")
PermissionError
没有文件权限
读取受保护的文件
AttributeError
对象没有该属性/方法
None.split()
ZeroDivisionError
除以零
10 / 0
ImportError
模块导入失败
import 不存在的库
NameError
变量未定义
print(未定义的变量)
json.JSONDecodeError
JSON 格式错误
json.loads("{broken}")
StopIteration
迭代器耗尽
next(空迭代器)
RecursionError
递归深度超限
无限递归函数

异常继承关系(部分):

BaseException └── Exception      ├── ValueError      ├── TypeError      ├── OSError      │    ├── FileNotFoundError      │    └── PermissionError      ├── LookupError      │    ├── KeyError      │    └── IndexError      └── ArithmeticError           └── ZeroDivisionError

理解继承关系很重要:捕获 OSError 就能同时捕获 FileNotFoundError 和 PermissionError。捕获 Exception 可以捕获几乎所有异常(但不推荐,太宽泛了)。


五、主动抛出异常:raise

有时候需要主动让程序抛出异常,用 raise

def set_age(age):    if not isinstance(age, int):        raise TypeError(f"age 必须是整数,收到的是 {type(age).__name__}")    if age < 0 or age > 150:        raise ValueError(f"age 的合法范围是 0-150,收到的是 {age}")    return agetry:    set_age("二十八")  # 触发 TypeErrorexcept TypeError as e:    print(f"类型错误:{e}")try:    set_age(200)   # 触发 ValueErrorexcept ValueError as e:    print(f"值错误:{e}")

在 except 中重新抛出:

def process_file(filepath):    try:        with open(filepath) as f:            data = f.read()    except FileNotFoundError:        print(f"日志:文件 {filepath} 不存在")        raise  # 重新抛出同一个异常,让上层调用者处理

六、自定义异常类

对于业务逻辑中的错误,建议创建自定义异常类,让错误信息更有语义:

# 定义自定义异常class ConfigError(Exception):    """配置相关错误"""    passclass DatabaseError(Exception):    """数据库相关错误"""    def __init__(self, message, error_code=None):        super().__init__(message)        self.error_code = error_codeclass UserNotFoundError(Exception):    """用户不存在"""    def __init__(self, user_id):        super().__init__(f"用户 ID {user_id} 不存在")        self.user_id = user_id
# 使用自定义异常def get_user(user_id):    users = {1: "Alice", 2: "Bob"}    if user_id not in users:        raise UserNotFoundError(user_id)    return users[user_id]try:    user = get_user(999)except UserNotFoundError as e:    print(f"错误:{e}")          # 用户 ID 999 不存在    print(f"查询的 ID:{e.user_id}")  # 999

自定义异常的好处:

  1. 代码语义清晰,一眼就知道什么业务出了什么问题
  2. 上层可以精准捕获特定业务错误,而不是捕获宽泛的 Exception
  3. 可以携带额外的错误上下文信息(如 user_id、error_code)

七、实战:给 JSON 文件操作加上完整异常处理

延续第 07 篇的学生成绩分析案例,现在我们加上完整的异常处理,让代码达到生产可用的标准:

import jsonfrom pathlib import Path# 自定义异常class DataFileError(Exception):    """数据文件相关错误"""    passdef read_students_data(filepath: str) -> dict:    """    读取学生数据 JSON 文件    Returns:        dict: 学生数据    Raises:        DataFileError: 文件不存在、权限不足或格式错误时    """    path = Path(filepath)    # 检查文件是否存在    if not path.exists():        raise DataFileError(f"数据文件不存在:{filepath}")    # 检查文件扩展名    if path.suffix.lower() != ".json":        raise DataFileError(f"文件格式不正确,需要 .json 文件,收到:{path.suffix}")    try:        with open(path, "r", encoding="utf-8") as f:            data = json.load(f)    except PermissionError:        raise DataFileError(f"没有读取文件的权限:{filepath}")    except json.JSONDecodeError as e:        raise DataFileError(f"JSON 格式错误(第 {e.lineno} 行):{e.msg}")    # 验证数据结构    if "students" not in data:        raise DataFileError("数据文件缺少 'students' 字段")    return datadef save_report(report: dict, filepath: str) -> None:    """    保存分析报告    Raises:        DataFileError: 写入失败时    """    path = Path(filepath)    try:        # 确保输出目录存在        path.parent.mkdir(parents=True, exist_ok=True)        with open(path, "w", encoding="utf-8") as f:            json.dump(report, f, indent=2, ensure_ascii=False)    except PermissionError:        raise DataFileError(f"没有写入文件的权限:{filepath}")    except OSError as e:        raise DataFileError(f"写入文件失败:{e}")def calculate_average(scores: dict) -> float:    """计算平均分,处理空字典的情况"""    if not scores:        return 0.0    return sum(scores.values()) / len(scores)def analyze_students(input_file: str, output_file: str) -> bool:    """    分析学生成绩    Returns:        bool: 成功返回 True,失败返回 False    """    try:        # 读取数据        data = read_students_data(input_file)        students = data["students"]        if not students:            print("⚠️ 数据文件中没有学生记录")            return False        # 处理成绩        results = []        for student in students:            # 防止 scores 字段缺失            scores = student.get("scores", {})            avg = calculate_average(scores)            results.append({                "name": student.get("name", "未知"),                "scores": scores,                "average": round(avg, 2)            })        # 排序        results.sort(key=lambda s: s["average"], reverse=True)        # 构建报告        report = {            "class": data.get("class", "未命名班级"),            "total_students": len(results),            "top_student": results[0]["name"],            "top_average": results[0]["average"],            "rankings": results        }        # 保存结果        save_report(report, output_file)        print(f"✅ 分析完成!结果已保存到 {output_file}")        print(f"🏆 最高分:{results[0]['name']}(平均 {results[0]['average']} 分)")        return True    except DataFileError as e:        # 业务层错误:给用户友好提示        print(f"❌ 数据处理失败:{e}")        return False    except Exception as e:        # 未预期错误:记录并报告        print(f"❌ 发生未知错误:{type(e).__name__}: {e}")        return False# 主程序if __name__ == "__main__":    success = analyze_students("students.json", "output/report.json")    if not success:        print("请检查输入文件后重试")

测试各种异常情况:

# 测试文件不存在analyze_students("不存在的文件.json", "output/report.json")# ❌ 数据处理失败:数据文件不存在:不存在的文件.json# 测试 JSON 格式错误analyze_students("broken.json", "output/report.json")# ❌ 数据处理失败:JSON 格式错误(第 3 行):Expecting ',' delimiter# 测试正常情况analyze_students("students.json", "output/report.json")# ✅ 分析完成!结果已保存到 output/report.json# 🏆 最高分:Alice(平均 91.67 分)

八、异常处理的最佳实践

✅ 应该做的:

# 1. 精准捕获具体异常类型,而不是一刀切捕获 Exceptionexcept FileNotFoundError:   # ✅ 好except Exception:           # ⚠️ 太宽泛,慎用# 2. 捕获异常后给出有意义的错误信息except ValueError as e:    print(f"输入值无效:{e}")   # ✅ 有上下文# 3. 用 finally 确保资源释放(虽然 with 已经处理了文件)try:    conn = get_db_connection()    # 操作数据库finally:    conn.close()   # ✅ 确保连接关闭# 4. 只捕获你知道如何处理的异常,其他的让它向上传播

❌ 避免的写法:

# 1. 沉默所有异常(最危险)try:    do_something()except:    # ❌ 没有指定类型,连 KeyboardInterrupt 都会被吞掉    pass# 2. 捕获了但什么都不做(bug 会被隐藏)try:    result = process(data)except Exception:    pass   # ❌ 发生错误了但程序继续,后续可能产生难以排查的 bug# 3. 用异常控制正常流程(性能差,可读性低)try:    value = my_dict["key"]except KeyError:    value = "default"# ✅ 改用:value = my_dict.get("key", "default")

小结

知识点
要点
基本结构
try-except-else-finally
,比 JS 多了 else(无异常时执行)
精准捕获
except ValueError
,比 except Exception 更好
获取异常
except ValueError as e
,用 str(e) 获取信息
主动抛出
raise ValueError("说明原因")
自定义异常
继承 Exception,为业务错误提供语义化类型
重新抛出
except
 块中直接 raise 不带参数

3 个核心原则:

  1. 捕获具体异常类型,不要一刀切 except Exception
  2. 捕获后一定要处理,不要默默 pass
  3. 用 finally 或 with 确保资源(文件、连接)一定被释放

第一阶段收官 🎉

恭喜!第 01-08 篇的 Python 基础入门系列就此完结。

你现在掌握了:

  • Python 环境搭建和基本语法
  • 列表、字典两大核心数据结构
  • 函数(含 Lambda、高阶函数)
  • 文件操作与 JSON 处理
  • 异常处理

这些已经足以让你写出实用的 Python 脚本。从下一篇开始,我们进入第二阶段:Python 进阶实用,第一个话题是——面向对象编程,用前端组件思维来理解 class


下篇预告

第 09 篇:Python 面向对象编程:用前端组件思维来理解 Class

类 = 组件模板,实例 = 组件实例。如果你理解 React 组件,那 Python 的 OOP 你一定能快速上手。下一篇见!


最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-27 18:38:47 HTTP/2.0 GET : https://f.mffb.com.cn/a/481377.html
  2. 运行时间 : 0.117781s [ 吞吐率:8.49req/s ] 内存消耗:4,667.00kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=61f7b2db8a9bdbbfce5db3e5178b52b3
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000734s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000527s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000231s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000278s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000486s ]
  6. SELECT * FROM `set` [ RunTime:0.000221s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000523s ]
  8. SELECT * FROM `article` WHERE `id` = 481377 LIMIT 1 [ RunTime:0.000890s ]
  9. UPDATE `article` SET `lasttime` = 1774607927 WHERE `id` = 481377 [ RunTime:0.003599s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000227s ]
  11. SELECT * FROM `article` WHERE `id` < 481377 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000368s ]
  12. SELECT * FROM `article` WHERE `id` > 481377 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000336s ]
  13. SELECT * FROM `article` WHERE `id` < 481377 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.000800s ]
  14. SELECT * FROM `article` WHERE `id` < 481377 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.020873s ]
  15. SELECT * FROM `article` WHERE `id` < 481377 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001289s ]
0.119389s