这是一个长镜头问题,但是如果在if块中发生错误,在php中有一种方法可以退出"if"语句并继续执行"else"语句吗?
例
if ($condition == "good")
{
//do method one
//error occurs during method one, need to exit and continue to else
}
else
{
//do method two
}
Run Code Online (Sandbox Code Playgroud)
当然可以在第一个if内部进行嵌套,但这看起来很hacky.
TIA
try {
//do method one
//error occurs during method one, need to exit and continue to else
if ($condition != "good") {
throw new Exception('foo');
}
} catch (Exception $e) {
//do method two
}
Run Code Online (Sandbox Code Playgroud)