CakeEmail how to determine failure before stack trace?

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:37:39

问题


I am trying to catch when an email fails so that I can save the required data in my database and I can attempt to send at a later date.

I thought the following should work as it does when using save()

        if ( $email->send() ) {
            //..success - works..
        } else {
            //..fail - never gets here, stack trace
        }


回答1:


obviously you are not in debug mode there. if you were, you would see that this actually throws an exception.

and you are catching sth there, just not the exception thrown :)

try this:

try {
    $success = $email->send();
    ...
} catch (SocketException $e) { // Exception would be too generic, so use SocketException here
    $errorMessage = $e->getMessage();
    ...
}

this way you can catch the exception and do sth here.



来源:https://stackoverflow.com/questions/14053112/cakeemail-how-to-determine-failure-before-stack-trace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!