thinkphp6-异常处理

开启调试模式 .env

APP_DEBUG = true

异常页面的模板文件 config/app.php

'exception_tmpl'   => app()->getThinkPath() . 'tpl/think_exception.tpl'

手动抛出异常

// 使用think自带异常类抛出异常
throw new \think\Exception('异常消息', 10006);

手动捕获异常

try {
    // 这里是主体代码
} catch (ValidateException $e) {
    // 这是进行验证异常捕获
    return json($e->getError());
} catch (\Exception $e) {
    // 这是进行异常捕获
    return json($e->getMessage());
}
posted @ 2021-10-18 15:06  胡勇健  阅读(1045)  评论(0)    收藏  举报