Laravel 5-如何捕获Mail :: send()错误? [英] Laravel 5 - How Do You Catch an Mail::send() Error?

查看:459
本文介绍了Laravel 5-如何捕获Mail :: send()错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下发送电子邮件的方法:

I have the following method which sends out an e-mail:

Mail::send('emails.configuration_test', array(), function($email)use($request){
    $email->to($request->test_address)->subject('Configuration Test');
});

如果上面的错误出了,我希望能够捕捉到异常.当我使用以下命令时:

If the above errors out, I'd like to be able to catch the exception. When I use the following:

try{
    Mail::send('emails.configuration_test', array(), function($email)use($request){
        $email->to($request->test_address)->subject('Configuration Test');
    });
}
catch(Exception $e){
    // Never reached
}

从未捕获到异常.相反,如果send()方法出错,我将获得Laravel stacktrace作为响应.

the exception is never caught. Instead I get a Laravel stacktrace as the response if the send() method errors out.

在这种情况下如何捕获异常?

How do I catch the exception in this case?

推荐答案

使用根名称空间\Exception可以解决问题.

Using the root namespace \Exception did the trick.

代替:

catch(Exception $e){
    // Never reached
}

我用过:

catch(\Exception $e){
    // Get error here
}

这篇关于Laravel 5-如何捕获Mail :: send()错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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