情景介绍:url请求是get方式,此次报错是测试post请求,异常返回错误信息是否正确,结果异常返回信息有误,返回信息不正确。
以下下报错信息,显示 自定义全局异常报错信息是传入HttpException参数给app\lib\exception\ExceptionHandle::render() 方法(本应传入think\Exception类型的参数),结果异常信息不能自动转换成正确的信息,查看think\Exception 和 HttpException 两个class类,都同时继承了\exception基类,也就是think\Exception 和 HttpException 两个class类并没有继承关系,二者互不关联,所以参数类型不能识别,将app\lib\exception\ExceptionHandle::render()的参数改为以基类的方式参数传入,就可解决此问题。
think\exception\ErrorException' with message 'Argument 1 passed to app\lib\exception\ExceptionHandle::render() must be an instance of think\Exception
think\exception\ErrorException: Argument 1 passed to app\lib\exception\ExceptionHandle::render() must be an instance of think\Exception, instance of think\exception\HttpException given,
| ( ! ) Fatal error: Uncaught exception 'think\exception\ErrorException' with message 'Argument 1 passed to app\lib\exception\ExceptionHandle::render() must be an instance of think\Exception, instance of think\exception\HttpException given, called in D:\phpStudy\PHPTutorial\WWW\humour\thinkphp\library\think\Error.php on line 47 and defined' in D:\phpStudy\PHPTutorial\WWW\humour\application\lib\exception\ExceptionHandle.php on line 25 | ||||
|---|---|---|---|---|
| ( ! ) think\exception\ErrorException: Argument 1 passed to app\lib\exception\ExceptionHandle::render() must be an instance of think\Exception, instance of think\exception\HttpException given, called in D:\phpStudy\PHPTutorial\WWW\humour\thinkphp\library\think\Error.php on line 47 and defined in D:\phpStudy\PHPTutorial\WWW\humour\application\lib\exception\ExceptionHandle.php on line 25 | ||||
| Call Stack | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.4658 | 1188352 | think\Error::appException( ) | ...\Error.php:0 |
| 2 | 0.4697 | 1241032 | app\lib\exception\ExceptionHandle->render( ) | ...\Error.php:47 |
| 3 | 0.4697 | 1241768 | think\Error::appError( ) | ...\Error.php:25 |
[1] ErrorException in ExceptionHandle.php line 25
Uncaught exception 'think\exception\ErrorException' with message 'Argument 1 passed to app\lib\exception\ExceptionHandle::render() must be an instance of think\Exception, instance of think\exception\HttpException given, called in D:\phpStudy\PHPTutorial\WWW\humour\thinkphp\library\think\Error.php on line 47 and defined' in D:\phpStudy\PHPTutorial\WWW\humour\application\lib\exception\ExceptionHandle.php:25
Stack trace:
#0 D:\phpStudy\PHPTutorial\WWW\humour\application\lib\exception\ExceptionHandle.php(25): think\Error::appError(4096, 'Argument 1 pass...', 'D:\\phpStudy\\PHP...', 25, Array)
#1 D:\phpStudy\PHPTutorial\WWW\humour\thinkphp\library\think\Error.php(47): app\lib\exception\ExceptionHandle->render(Object(think\exception\HttpException))
#2 [internal function]: think\Error::appException(Object(think\exception\HttpException))
#3 {main}
thrown
class ExceptionHandle extends Handle{private $code;private $msg;private $errorCode;// 需要返回客户端当前的请求URLpublic function render(Exception $e){if ($e instanceof BaseException) {// 如果是自定义异常$this->code = $e->code;$this->msg = $e->msg;$this->errorCode = $e->errorCode;} else {if(config('app_debug')){return parent::render($e);
Call Stack
- in ExceptionHandle.php line 25
- at Error::appShutdown()
版权声明:本文为ifyouwanttogo原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。