<?phpclass aaException extends Exception{
public function errorMessage()
{
$error="fuuuuuuuck";
return $error;
}
}
try{
$m=exec("python 2.py");
print "hello";
$n=exec("python 1.py");
if(!$m){
throw new Exception("failed1111");}
if(!$n){
throw new aaException("ffffaaaa");}
}
catch(Exception $e){
echo $e->getmessage();
}
catch(aaException $e){
echo $e->errorMessage();
}
?>
1.py 2.py都没有,应该抛出两个异常,为什么只打印failed1111

解决方案 »

  1.   

    楼上正解,而且你的代码结构有点怪啊,应该是下面这样的吧:class aaException extends Exception{
    public function errorMessage()
    {
    $error="fuuuuuuuck";
    return $error;
    }
    }
    try{
    $m=exec("python 2.py");
    print "hello";
    if(!$m){
    throw new Exception("failed1111");
    }
    $n=exec("python 1.py");
    if(!$n){
    throw new aaException("ffffaaaa");
    }
    }
    catch(Exception $e){
    echo $e->getmessage();
    }
    catch(aaException $e){
    echo $e->errorMessage();
    }
      

  2.   

    我想再次执行最后一个catch,即打印"fuuuuuuuck" (1.py是空的,$n本来就有错),该怎么写啊?谢谢!