【问题标题】:Omnipay Exception not being caught未捕获 Omnipay 异常
【发布时间】:2016-09-24 22:44:23
【问题描述】:

使用 Craft CMS 实施 Omnipay。 Craft 和 Onmipay 相对较新,但希望我的一般概念知识不会在这里消失:

这看起来很简单,应该使用 try/catch 块来捕获异常吗?

// 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 类的堆栈跟踪,它会根据我犯的任何故意的信用卡错误引发异常。

为什么它没有捕获异常并执行我的 catch 块? Omnipay/Craft 需要做什么才能捕获此异常,以便我可以将用户重定向到列出错误的正确页面?

【问题讨论】:

    标签: exception-handling try-catch omnipay


    【解决方案1】:

    尝试改变这个:

    } catch (Exception $e) {
    

    到这里:

    } catch (\Exception $e) {
    

    【讨论】:

    • 非常感谢。我能够查明为什么它会起作用而不是没有。再次感谢!
    猜你喜欢
    • 2010-09-28
    • 2012-05-31
    • 1970-01-01
    • 2018-01-01
    相关资源
    最近更新 更多