Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Perl function calls.

by hardburn (Abbot)
on Jul 07, 2014 at 14:53 UTC ( #1092593=note: print w/replies, xml ) Need Help??


in reply to Perl function calls.

What did you do to test it? Were you expecting a failure? Are you sure that this test method actually produces a failure?

Of note, the call to open in the sub won't throw an error on its own. You need to check its return value:

open my $p, '<', $filename or return "Could not open $filename: $!";

Which should be compatible with the way you intended to catch errors. However, I'll also point out that or die "error message" tends to be the preferred way of doing this rather than or return "error message".


"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^2: Perl function calls.
by user786 (Sexton) on Jul 07, 2014 at 15:05 UTC

    This method actually did not produce any failure. Yes that correct,die is preferred way. I have used auto die in the script. But I'd like to know/learn how it works with the return message.

    It would be really helpful for me if you can help me understand it.

      Well, if it didn't return failure, then I'm not sure how you can say your error code didn't work. If there's no failure for it to catch, then of course it won't run.

      As it is, your error code should work fine if the function is expected to return an error string on failure. Since the function doesn't return an error string in any branch, the error will never be picked up.


      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2019-09-23 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (279 votes). Check out past polls.

    Notices?