开启调试模式 .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());
}