这在 PHP 中可行吗?
try {
$obj = new Clas();
if ($obj->foo) {
// how to exit from this try block?
}
// do other stuff here
} catch(Exception $e) {
}
我知道我可以将其他内容放在 {}
之间,但这会增加更大代码块上的缩进,我不喜欢它:P
最佳答案
用goto当然!
try {
$obj = new Clas();
if ($obj->foo) {
goto break_free_of_try;
}
// do other stuff here
} catch(Exception $e) {
}
break_free_of_try:
关于php - 从 try/catch block 中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16469596/