使用Exception 和 HttpResponseException有什么区别?

来源:7-17 利用authbase处理登录拦截器

walk205

2020-07-08

public function show(...$args) {
    throw new \think\Exception(...$args);
}

用这个抛出异常 Http.php里面也可以正常接收,不理解换成HttpResponseException反尔还要在Http.php里面多加个判断 是为什么?

写回答

1回答

walk205

提问者

2020-07-08

我在AuthBase里面验证完权限也是可以直接抛出异常

   public function initialize()
   {
       parent::initialize(); // TODO: Change the autogenerated stub
       $this->accessToken = request()->header('access_token');
       if(!$this->accessToken || !$this->isLogin()){
//            return $this->show(config('message.error.login_not'), config('status.login_not'));
           throw new \think\Exception(config('message.error.login_not'), config('status.login_not'));
       }

   }

老师用HttpResponseException是有什么性能稳定上的考虑?

0
2
stevenfung
HttpResponseException是可以redirect到一个页面地址 而think\Exception是一个异常信息的抛出, 可以 throw new \think\Exception(...$args); 这样args里的格式就需要改变了 不可以 throw new \think\Exception(show(...$args)); 使用HttpResponseException(show(...$args)); args的格式就和我们一般的返回信息一致。 主要是这个用处吧。
2020-10-07
共2条回复

全流程开发 TP6.0实战高并发电商服务系统

一课就能掌握TP6.0基础及运用,打造完整高并发的电商后端项目

1463 学习 · 1332 问题

查看课程