PHP Catch异常运行顺序

时间:2014-05-28 20:04:09

标签: php exception try-catch

我在下面的代码中有一些try-catch异常和if语句,我正在尝试编写。

try {
    $user = new User($userId);
    if ($user->getEmailToken() == $emailToken) {
        try {
            $user->setEmailToken('');
            $user->setEmailVerified(1);
            $user->store()
            fMessaging::create('success', 'verify', 'Your email has been verified. Thank you.');
            fURL::redirect('/account/confirm.php');
        } catch (fExpectedException $e) {
            fMessaging::create('errorMessage', 'verify', $e->getMessage());
            fMessaging::create('error', 'verify', "Your email could not be verified at this time, please be sure the link from the email was copied correctly.");
        }
    } else {
        fMessaging::create('errorMessage', 'verify', 'User token does not match.');
        fMessaging::create('error', 'verify', "Your email could not be verified at this time, please be sure the link from the email was copied correctly.");
    }
} catch (fExpectedException $e) {
    fMessaging::create('errorMessage', 'verify', $e->getMessage());
    fMessaging::create('error', 'verify', "Your email could not be verified at this time, please be sure the link from the email was copied correctly.");
}

我的问题是,当它运行时,它以某种方式将电子邮件令牌值设置为''在运行if($ user-> getEmailToken()== $ emailToken)语句之前,它总是变为false。

实际上,不仅仅是设置它,它还将电子邮件验证值设置为1并将我的用户保存在数据库中。我是否在设置try-catch异常的方式上做错了什么?

0 个答案:

没有答案