I'm using try-catch
for years, but I never learned how and when to use finally
, because I never understood the point of finally
(I've read bad books)?
I want to ask you about use of finally
in my case.
My code example should explain everything:
$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);
}
Is this correct use of finally?
More precise question:
Shall I use finally
(in future PHP versions or other languages) for handling "create something if it not exists" operations?