【发布时间】:2009-12-26 11:31:09
【问题描述】:
我试图在 PHP 中使用异常来避免多个 if-then-else 块。但是,当我尝试捕获异常时,我收到错误 Parse error: syntax error, unexpected T_CATCH in /directory/functions.php on line 66。我的投掷和接球有什么问题吗?
function doThis($sSchool, $sDivision, $sClass, $sUsername, $sCode,$query1,$query2)
{
connectDb();
global $dbConnection;
$sDivisionIdArray = mysqli_query($dbConnection,$query1);
if ($sDivisionIdArray==false){throw new Exception ();}
$sDisplayQueryArray = mysqli_query($dbConnection,$query2);
if ($sDisplayQueryArray==false){throw new Exception ();}
catch (Exception $e) // This is line 666
{echo ('Sorry, an error was encountered.');}
}
【问题讨论】:
标签: php exception exception-handling throw