Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Try::Tiny catch block with $_ eq ''

by dd-b (Monk)
on May 16, 2013 at 22:39 UTC ( #1033921=note: print w/ replies, xml ) Need Help??


in reply to Re: Try::Tiny catch block with $_ eq ''
in thread Try::Tiny catch block with $_ eq ''

I'm using Try::Tiny because they claim it's hard to really use eval correctly to do this, but I could switch back and hope I don't hit their problem cases, at least as a test. We shall see. I've been putting eleventy-dozen $logger->trace("point 17"); statements through the code it comes out of unexpectedly to narrow down where it is. Setting up the database for a test run and then analyzing the log is not as simple as I could hope it was (though far better than my test setup procedure two weeks ago :-) ).


Comment on Re^2: Try::Tiny catch block with $_ eq ''
Select or Download Code
Re^3: Try::Tiny catch block with $_ eq ''
by vsespb (Hermit) on May 16, 2013 at 22:45 UTC
    I think it's hard when there are nested evals. Otherwise it's pretty simple, if you read the docs carefully.

      That's not the main eval gotcha that Try::Tiny seeks to solve. Amongst the things mentioned in Try::Tiny's documentation are:

      • It is possible to throw an exception which is considered false in a boolean context, thus breaking if ($@). Try::Tiny isn't fooled by that.
      • If a DESTROY method calls eval then an object used within your eval could potentially clobber $@. Try::Tiny creates a copy of $@ that is safe, and passes it as a parameter to the catch block.

      These errors are fairly rare in practice, but extremely difficult to figure out when they do happen. People who have been burned by them in the past tend to appreciate Try::Tiny quite a lot.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
        It is possible to throw an exception which is considered false in a boolean context
        Don't use
        if ($@)
        Use
        unless defined eval { somecode(); 1; }
        If a DESTROY method calls eval then an object used within your eval could potentially clobber $@.
        True, well, I count it as nesting evals.

        UPD:

        I am not trying to tell that eval is better than Try::Tiny. I just think that OP might want to temporary change one statement to see how it works with plain eval{}.

        For cases when people use nested exceptions try/catch blocks, heavy use Exception handling pattern, heavy use OOP (with descructors), Try::Tiny is much better than eval{} (it's impossible to work with eval actually)

        But there are valid cases when people don't need to use Exceptions/OOP in so heavy way. Then it's perfectly valid to simply use eval then. And learning eval gotchas is as hard as learning Try::Tiny gotchas.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (15)
As of 2014-07-30 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls