Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by tobyink (Abbot)
on May 16, 2013 at 21:39 UTC ( #1033914=note: print w/ replies, xml ) Need Help??


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

The only "errors" that Try::Tiny cares about are die. (Though this also includes Carp::croak(), Carp::confess(), etc, because they call die internally.)

The only way I can reproduce $_ eq "" is to call die($e) where $e is a blessed object with overloading, that overloads eq or "" to compare equal to the empty string.

$ perl -MTry::Tiny -MData::Dumper -e'my $e = do { package E; use overl +oad q[""] => sub {""}, fallback=>1; bless [] }; try { die $e } catch +{ print Dumper($_ eq "") }'

Update: oh yes; the other thing worth thinking about... are you using my $_ anywhere in this lexical scope? (Or given/when?) The lexical version of the $_ variable could be masking the global one (which is what Try::Tiny uses). Try starting your catch block with our $_; and see if that makes any difference.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: Try::Tiny catch block with $_ eq ''
Select or Download Code
Re^2: Try::Tiny catch block with $_ eq ''
by dd-b (Monk) on May 16, 2013 at 22:37 UTC

    The "other ways to die" I know of, have checked for. I am not overloading eq or stringifiction, or throwing objects directly myself, in this code. I have no explicit my $_;. Hadn't thought about that (but would be unlikely to do it, too). However, there is given/when around some in this general area. I'll check the details of what that does. I don't think I'm inside it, though, so probably not the cause; but hadn't thought how that might interact, so I need to check. I don't think the catch blocks contain any given/when, though; still, I hadn't thought of that, need to check the possible cases, thanks!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-10-23 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls