如何绕过Laravel异常处理 [英] How to bypass Laravel Exception handling

查看:97
本文介绍了如何绕过Laravel异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种检查用户是否具有有效会话信息的方法.应该会抛出一个异常Guzzle\Http\Exception\BadResponseException,但是当我尝试捕获它时:

I have a method that checks if a user has valid Session info. This is supposed to throw an Exception, Guzzle\Http\Exception\BadResponseException but when I try to catch it :

catch (Guzzle\Http\Exception\BadResponseException $e) 
{
    return false;
} 
return true

Laravel没有获得此代码,而是立即开始其自身的错误处理.还有关于如何绕过Laravels自己的实现并使用我自己的Catch的想法.

Laravel doesn't get to this code and immediately starts it's own error handling. And ideas on how to bypass Laravels own implementation and use my own Catch.

我刚刚发现Laravel使用与Symfony相同的Exception处理程序,因此我还添加了Symfony2标记.

I just found out Laravel uses the same Exception handler as Symfony, so I also added the Symfony2 tag.

我通过禁用Guzzle异常并手动检查return标头解决了该问题.这有点捷径,但是在这种情况下,它可以完成工作.感谢您的答复!

I sort of fixed the issue by disabling Guzzle exceptions and checking the return header manually. It's a bit of a short cut but in this case, it does the job. Thanks for the responses!

推荐答案

实际上,可以在Laravel中捕获此异常,您只需要尊重(并理解)命名空间即可:

Actually this exception can be catched in Laravel, you just have to respect (and understand) namespacing:

如果有

namespace App;

你做

catch (Guzzle\Http\Exception\BadResponseException $e) 

PHP知道您正在尝试

PHP understands that you are trying to

catch (\App\Guzzle\Http\Exception\BadResponseException $e) 

因此,要使其正常工作,您只需要使用根斜杠即可:

So, for it to work you just need a root slash:

catch (\Guzzle\Http\Exception\BadResponseException $e) 

它将起作用.

这篇关于如何绕过Laravel异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆