Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by vsespb (Hermit)
on May 17, 2013 at 12:38 UTC ( #1033967=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^5: Try::Tiny catch block with $_ eq ''
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-07-05 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls