-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
finally { } block is not always called #7
Comments
The only way how to fix finally { } block (without XS code) is to use scope guards, similarly to Try::Tiny... |
I've never thought of such a use case |
Look at the last test in Try-Tiny/t/finally.t. This is the most used use-case.
|
Yes this was introduced in v0.25 with this commit p5sagit/Try-Tiny@8035202 I'll try to fix and add tests, this will add some overhead to the execution time. |
This is not so easy as Try::Catch supports throwing errors from finally block. Try::Tiny does not support it... But I have some "hack" in my mind which should supports throwing errors when jump/goto is not used. Wait some time and I will try to write it :-) |
Same thought here so LOL that would be much appreciated :) |
I tried to fix this problem, but do not see any solution in pure perl code which ensure that finally { } block will be always called and also finally { } block can die. This is really limitation of perl. Next I tried hack to create scope guard for finally { } block and also call finally { } block before exiting whole Try::Catch::try implementation. In this case finally block signal scope guard if it was called or not. It would allowed me to propagate die from finally { } block if some jump/goto was not used. But my implementation again not worked correctly (problems with fork() and exit()) and I guess this is not easy to write correctly... Moreover such implementation slow down Try::Catch module... and we already have Try::Tiny which implement this support (but without die propagation in finally { } blocks). So I would suggest to document this bug in module POD section with information that using jump/goto or fork/exit is not supported in this module. I understood that primary goal of this module is speed and those who needs different support for finally { } blocks then should use Try::Tiny. |
I'm sorry for the delay and I really appreciate your working on this. |
Hm... I was thinking about it and I do not feel that it a good idea to have non-working finally { } block implementation even it will be somehow documented... Maybe it would be better to completely remove finally { } support and not provide false experience and view that finally { } block is provides, so it should work correctly.... But it is up to you how you decide... In this bug report I reported that current implementation is non-working and broken... If aim of this module is speed, then maybe it really make sense no support for finally { } block. Anyway, see this commit in DBIx::Class module: Try::Tiny is no so tiny and slow... So looks like some modules already needs some lightweight try { } catch { } implementation even without finally { } support... |
@pali oops missed this one :( I think you're right again, keeping the finally with this odd behavior will trick users, as the whole point of finally block is to be executed on all situations except in up-normal situations like system exit, skipping the finally block is the same as putting code outside the try/catch!! I just uploaded |
Yes, as I wrote it would be really better to remove not-fully-working finally { } block support... |
Are you going to to remove that not-fully-working |
When doing jump from try { } or catch { } block outside of block then finally is not called.
Example 1:
Example 2:
finally was called
is never printed even it was specified in finally { } block which should be always called.When both examples are used with
Try::Tiny
insteadTry::Catch
then examples correctly printfinally was called
.This makes finally { } block with
Try::Catch
totally unusable.The text was updated successfully, but these errors were encountered: