跳转方法在try..catch中使用注意

浏览:1159 发布日期:2017/03/10 分类:ThinkPHP5专区
和tp3不同,tp5中的跳转是通过 HttpResponseException 实现的,也就是说如果你在 try ... catch 中使用了控制器的 success error 方法,注意异常区别处理.try {
    //...业务逻辑
   $this->success("ok");
} catch (\RuntimeException $e) {
   $this->error("hahahaha")
}
这段代码最终显示的会是 error 提示。我建议要么不要捕获 RuntimeException 和 Exception ,要么就把 success 放到 try..catch块下面try {
    //...业务逻辑
} catch (\RuntimeException $e) {
   $this->error("hahahaha")
}
$this->success("ok");
最佳答案
评论( 相关
后面还有条评论,点击查看>>