相关疑难解决方法(0)

我可以像这样使用try-catch-finally吗?

我已经使用try-catch多年了,但我从来没有学过如何以及何时使用finally,因为我从未明白finally(我读过坏书)的意思?

我想问你finally在我的案子中的用法.

我的代码示例应该解释一切:

$s = "";

$c = MyClassForFileHandling::getInstance();

try
{
    $s = $c->get_file_content($path);
}

catch FileNotFoundExeption
{
    $c->create_file($path, "text for new file");
}

finally
{
    $s = $c->get_file_content($path);
}
Run Code Online (Sandbox Code Playgroud)

终于正确使用了吗?

更准确的问题:

我可以使用finally(在未来的PHP版本或其他语言中)处理"创建一些不存在的东西"操作吗?

php try-catch-finally

15
推荐指数
1
解决办法
3万
查看次数

标签 统计

php ×1

try-catch-finally ×1