We don't bite newbies here... much | |
PerlMonks |
Try::Tiny vs. TryCatch: assigning a value to a variable inside of the try-blockby v_melnik (Scribe) |
on Oct 08, 2014 at 13:46 UTC ( [id://1103173]=perlquestion: print w/replies, xml ) | Need Help?? |
v_melnik has asked for the wisdom of the Perl Monks concerning the following question: I almost have no hope that there is a way to achieve what I want, but I'd better ask more experienced colleagues than make a mistake. I like Try::Tiny very much, because it makes possible to do so something like that:
Alas, we can't do it with TryCatch, because it doesn't return the result the try-block, so TryCatch forces us to do something like that:
As for me, TryCatch is better, because it allows us to control the flow by return/next/last and other commands and it can choose the catch-block depending on the class of the exception (I really love this feature!), but the only thing I can't bear with - that I must declare the resulting variable by a separate my-command before to use try. What do you think, is there any ways to make the try-block to return a value? Thank you! UPD:Lots of thanks for all ideas. I decided to keep using TryCatch, but I'll declare all variables in the beginning of the block:
I think, declaring all variables in the beginning of a block is a pretty good manner. Some of languages are quite strict about that, so I can just stop indulging myself with declaring them wherever I want. :)
V.Melnik
Back to
Seekers of Perl Wisdom
|
|