PHP 5.5 has implemented finally
to try-catch
. My doubt is: when exactly try-catch-finally
that might be more helpful than just I write below try-catch
?
Example, difference between:
try { something(); }
catch(Exception $e) { other(); }
finally { another(); }
Instead of, just:
try { something(); }
catch(Exception $e) { other(); }
another();
Can send me some example that is common to this case?
Notes:
- I talk about
try-catch-finally
, and not abouttry-finally
, only; - There are some "features" cool, like you cancel current exception and throw a new-other-exception on finally (I don't tried, I read here). I don't know if it is possible without
finally
; - Would not be more useful something like
notcatch
? So I can run a code iftry
goes without an exception. hehe