未捕获 Omnipay 异常
Omnipay Exception not being caught
使用 Craft CMS 实施 Omnipay。 Craft 和 Onmipay 相对较新,但希望我的一般概念知识不会在这里消失:
这看起来很简单,应该用 try/catch 块 no?
捕获异常
// Validate on Omnipay Credentials
$formInputData = array(
'number' => $info->CardNumber,
'expiryMonth' => $info->ExpireMonth,
'expiryYear' => $info->ExpireYear,
'cvv' => $info->SecurityCode,
'first_name' => $info->Cardholder,
'billingAddress1' => $info->CardAddress,
'billingCity' => $info->CardCity,
'billingState' => $info->CardState,
'billingPostcode' => $info->CardZip,
);
//try/catch for Omnipay Invalid Card Exception
try{
$card = new CreditCard($formInputData);
$card->validate();
} catch (Exception $e) {
echo 'blah';
}
这并没有捕捉到异常,而是我被重定向到一个异常页面,内容如下:
Omnipay\Common\Exception\InvalidCreditCardException
Card number should have 12 to 19 digits
然后是对 CreditCard class 的堆栈跟踪,它根据我故意犯的任何信用卡错误抛出异常。
为什么它没有捕获异常并执行我的 catch 块? Omnipay/Craft 需要做什么才能捕获此异常,以便我可以将用户重定向到列出错误的正确页面?
尝试改变这个:
} catch (Exception $e) {
为此:
} catch (\Exception $e) {
使用 Craft CMS 实施 Omnipay。 Craft 和 Onmipay 相对较新,但希望我的一般概念知识不会在这里消失:
这看起来很简单,应该用 try/catch 块 no?
捕获异常// Validate on Omnipay Credentials
$formInputData = array(
'number' => $info->CardNumber,
'expiryMonth' => $info->ExpireMonth,
'expiryYear' => $info->ExpireYear,
'cvv' => $info->SecurityCode,
'first_name' => $info->Cardholder,
'billingAddress1' => $info->CardAddress,
'billingCity' => $info->CardCity,
'billingState' => $info->CardState,
'billingPostcode' => $info->CardZip,
);
//try/catch for Omnipay Invalid Card Exception
try{
$card = new CreditCard($formInputData);
$card->validate();
} catch (Exception $e) {
echo 'blah';
}
这并没有捕捉到异常,而是我被重定向到一个异常页面,内容如下:
Omnipay\Common\Exception\InvalidCreditCardException
Card number should have 12 to 19 digits
然后是对 CreditCard class 的堆栈跟踪,它根据我故意犯的任何信用卡错误抛出异常。
为什么它没有捕获异常并执行我的 catch 块? Omnipay/Craft 需要做什么才能捕获此异常,以便我可以将用户重定向到列出错误的正确页面?
尝试改变这个:
} catch (Exception $e) {
为此:
} catch (\Exception $e) {