这里是我的代码:尝试多个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