php - 在抛出异常时在 try-catch 中使用 continue 来防止脚本终止
问题描述
我想将旧代码转换为使用异常,但在抛出异常时它不应该停止。那是旧代码:
function update()
{
foreach ($this->instances as $id => $instance)
{
if ($instance->exists())
{
if (!$instance->save())
{
$this->setError($instance->getError());
continue;
}
continue;
}
}
如果我想使用 try catch 块,是否需要使用 continue 来避免脚本停止?那是 try-catch 的代码:
function update()
{
foreach ($this->instances as $id => $instance)
{
if ($instance->exists())
{
try
{
$instance->save();
}
catch (exception $e)
{
echo $e->getMessage();
}
}
}
解决方案
推荐阅读
- c# - 避免覆盖图像文件并创建一个新文件
- android - 如何从 Activity 将片段启动到 viewpager?
- android - 安卓分享链接在打开应用后不可用
- node-serialport - serialport node.js 读取缓冲区问题
- xamarin.forms - 如何在标题栏中添加文本框?
- python - 无法分配查询集,必须是实例
- android - 无法检查用户是否已经存在于android firebase
- android - 如何在android中添加库改造?
- ios - IOS-单击推送通知时应用程序崩溃仅在应用程序统计被杀死时发生
- c++ - 无法找出以下程序中的错误