php - 从 try/catch block 中断

标签 php exception try-catch

这在 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/

相关文章:

php - 我有一个 base64 编码的 png,如何将图像写入 PHP 文件?

c# - trye 上的 Azure 服务总线异常完成消息

javascript - 在捕获之前编辑抛出的错误?

java - 如何从 try-with-resources 捕获异常?

sql-server - SQL Server 中的 Try-Catch?

c# - Try/Catch 方法错误 ASP.NET

java - 从 MySQL 获取数据到 Android 应用程序

php - mysqli prepare and insert statements using variables插入值和变量语法错误

php - 比较两个函数的结果,如果相同则隐藏结果

java - 在 Facelets 页面中显示异常堆栈跟踪