本文介紹了在 Cakephp 3 中捕獲異常:不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我嘗試在 Cakephp v3.0 中捕獲異常,但它似乎不起作用:
I try to catch exceptions in Cakephp v3.0, but it doesn't seems to work :
try{
$email = new Email('default');
$email->from([Configure::read('email') => Configure::read('emailName')])
->to(Configure::read('email'))
->bcc($to)
->subject(__('XXXX') . ' : ' . __('XXXX'))
->template('fail', 'default')
->emailFormat('html')
->send();
} catch (Exception $ex) {
}
它沒有捕獲異常:
Could not send email: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() CakeNetworkExceptionSocketException
很煩人,我用它來捕獲本地服務器上發(fā)送的失敗電子郵件.
Pretty annoying, I'm using it to catch fail email send on a local server.
非常感謝.
推薦答案
在這里添加答案,只是為了降低未回答問題的統(tǒng)計數(shù)據(jù):
Adding the answer here, just to bring dow the unanswered questions stats down:
您需要使用 Exception
或更具體的命名空間異常名稱
You need to use Exception
or a more specific, namespaced, exception name
try {
// code
} catch (Exception $e) {
// error
}
這篇關于在 Cakephp 3 中捕獲異常:不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!