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

Re^3: Can I catch a die from someone else's module?

by perlfan (Vicar)
on May 02, 2022 at 01:39 UTC ( [id://11143509]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Can I catch a die from someone else's module?
in thread Can I catch a die from someone else's module?

I think it depends; for this module I would do this since it returns the reference if successful.
local $@; my $book = eval { Spreadsheet::Read->new($file); };
or
local $@; my $book; my $ok = eval { $book = Spreadsheet::Read->new($file); 1; };
The second example seems like "more work" to handle the error and is a lot messier. So in this case adding the "1" is superfulous since the called sub actually returns something (or doesn't).

A case where I'd use 1; with an or undef thrown in:

local $@; my $ok = eval { doSomethingButDontWantReturnValButCouldDie() or undef; 1; };
I think ultimately, the answer is like I stated above, it depends - on what you're doing and expecting; and how you tend to check for/handle exceptions.

I've also done this; but usually it's a game time decision for me.

local $@; my $ok = eval { doSomethingButDontWantReturnValButCouldDie(); 1; } or undef;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-18 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found