這裏是我的代碼:嘗試多個catch
error_reporting(0);
$mysqli=new mysqli("localhost",'root','','alex');
try{
if($mysqli->connect_errno){
throw new Exception("Database error!");
}else{
$query=$mysqli->query("Select companie,sum(suma) as suma from muncitori group by companie");
if(!$query){
throw new LastException("Query failed!");
}
}
while($result=$query->fetch_array()){
echo "Compania $result[companie] a cheltuit suma $result[suma] lei<br>";
}
}catch (Exception $e){
echo $e->getMessage();
}catch (LastException $e){
echo $e->getMessage();
}
class LastException extends Exception{}
如果我的查詢失敗,我拋出異常,(LastException $ S)catch塊未捕獲異常,但(例外$ E)抓住它。哪裏有問題?爲什麼Exception捕獲ExceptionException異常?
請更改您的問題 – sectus