我對整個try catch塊感到困惑。我明白如果拋出一個異常它執行catch塊,但是我有一個關於在try塊內使用return的問題。瞭解try catch塊
try {
//other logic is here
//this is in laravel and sends the user back and should stop operation
if (foo != bar) {
return Redirect::back()->with_message('This auction is closed.', 'error');
}
} catch (Exception $e) {
return $e->getMessage();
}
所以我的問題是:是否可以在try塊內結束操作?我會遇到一個錯誤,其中返回被忽略(或者被認爲是一個異常?)並且代碼繼續?再一次,我對此很新。