Thinkphp5.0之异常处理

Posted 夜微微微的凉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Thinkphp5.0之异常处理相关的知识,希望对你有一定的参考价值。

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

异常处理接管

1.修改config.php

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

// 异常处理handle类 留空使用 hinkexceptionHandle
‘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‘));
}
}
}

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



















以上是关于Thinkphp5.0之异常处理的主要内容,如果未能解决你的问题,请参考以下文章

thinkphp5.0--编写api,返回json格式

重学SpringBoot系列之统一全局异常处理

Python 基础之 异常处理

python之异常处理机制

Python之异常处理模块与包

python之异常处理