Thinkphp5.0之异常处理

1.默认异常处理
在调试模式下,系统默认展示的错误页面:
请输入图片描述

异常处理接管

1.修改config.php

'app_debug' => false,
2.在配置文件里添加如下代码

// 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '\\app\\common\\exception\\Http',
3.添加错误异常模块代码:

<?php
namespace appcommonexception;
use thinkexceptionHandle;
class Http extends Handle
{

public function render(\Exception $e){
if(config('app_debug')){
//如果开启debug则正常报错
return parent::render($e);
}else{
//重定向页面
header("Location:".url('index/index/index'));
}
}
}

加完这些东西,就不会出现那些烦人的报错代码啦!

原文地址:https://www.cnblogs.com/honely/p/10184524.html