本文介绍了CakeEmail如何在堆栈跟踪之前确定失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要在电子邮件失败时捕获,以便我可以在我的数据库中保存所需的数据,我可以尝试稍后再发送。
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.
我以下应该使用 save()
if ( $email->send() ) {
//..success - works..
} else {
//..fail - never gets here, stack trace
}
推荐答案
显然你不是在调试模式下。
如果你是,你会看到这实际上抛出一个异常。
obviously you are not in debug mode there.if you were, you would see that this actually throws an exception.
并且你正在捕获sth,只是没有抛出异常:)
and you are catching sth there, just not the exception thrown :)
试试这个:
try {
$success = $email->send();
...
} catch (SocketException $e) { // Exception would be too generic, so use SocketException here
$errorMessage = $e->getMessage();
...
}
这种方式你可以捕获异常sth here。
this way you can catch the exception and do sth here.
这篇关于CakeEmail如何在堆栈跟踪之前确定失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!