我想在我的代码的一部分中使用异常来处理错误,但如果代码失败,我希望脚本继续.我想记录错误.有人可以帮我解决这个问题吗?
try{
if($id == 4)
{
echo'test';
}
}
catch(Exception $e){
echo $e->getMessage();
}
echo'Hello, you should see me...'; <------ I never see this.. No errors, just a trace.
Run Code Online (Sandbox Code Playgroud)
你必须抓住异常:
// some code
try {
// some code, that might throw an exception
// Note that, when the exception is thrown, the code that's after what
// threw it, until the end of this "try" block, will not be executed
} catch (Exception $e) {
// deal with the exception
// code that will be executed only when an exception is thrown
echo $e->getMessage(); // for instance
}
// some code, that will always be executed
Run Code Online (Sandbox Code Playgroud)
以下是您应该阅读的一些内容: