抛出异常后尝试行仍然触发

时间:2015-02-17 20:42:21

标签: php laravel-4 try-catch

我试图在我的两个php文件之间尝试一下try / throw / catch结构。我已经死了并且将线路放入以缩小我的错误所在的位置,即die(var_dump(...))线通常不存在。

这是我的try / catch块:

public function sendWelcome(){
    try{

        $this->welcome->sendWelcomeforAllNewUsers();
        die(var_dump(["here", __FILE__ , __LINE__]));

    }catch(\Exception $exception){

        Session::flash('error', $exception->getMessage());
        return Redirect::to('main');

    }

    Session::flash('success', "Welcome emails have been sent");
    return Redirect::route('admin.importedAccounts');
}

这是我的方法可以抛出异常:

protected function sendWelcomeToNewUsers(){

    if(empty($this->newUsers)){
        throw new \Exception('There are no new users to send welcome emails to.');
    }

    foreach($this->newUsers as $user){
        $this->sendWelcome($user->getLogin());
    }
}

我现在知道$this->newUsers是空的(确实评估为真),但是我仍在击中我的骰子和转储线,这是try块中的下一行。

我添加了一个die和dump line to if抛出异常只是为了确保它被解雇:

    if(empty($this->newUsers)){
        die(var_dump(["here", __FILE__ , __LINE__]));
        // when I add this in and try it in the browser I definitely die here.
        throw new \Exception('There are no new users to send welcome emails to.');
    }

我在这里做错了吗?即使抛出异常,是否有某些东西可以让尝试仍然触发?

0 个答案:

没有答案
相关问题