我被困在我工作的一个错误记录片的工作,最终却演化成了以下内容:PHP尝试捕捉最后发出
$errorMsg = 'No Errors Detected';
try{
nonexistentfunction(); //Basically something here will not work
}catch(Exception $e){
$errorMsg = 'Oh well, something went wrong';
}finally{
$this->logger->log($errorMsg);
}
然而,每一次记录仪记录,提示“无检测到错误',而应该记录'哦,出错了',因为我抛出了一个异常(在这个例子中找不到方法,但是可能会发生任何异常)。
如何获取catch()块中的代码执行?它似乎并没有执行!
您正在使用什么版本的PHP? – fubar
你在使用命名空间吗?尝试'} catch(\ Exception $ e){' – ishegg
@RahulBhatnagar尝试使用'throw new \ Exception(“Custom exception!”)''而不是'nonexistentfunction()' –