Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How many different ways can Perl code fail?

by ikegami (Patriarch)
on Jan 13, 2009 at 21:30 UTC ( [id://736090]=note: print w/replies, xml ) Need Help??


in reply to Re: How many different ways can Perl code fail?
in thread How many different ways can Perl code fail?

Check for eval returning undef + $@ != null.

Checking $@ is a bit unreliable. Better:

if (!eval { ...; 1 }) { ...error handler... }

Or if you need the return value:

my $rv; if (!eval { $rv = ...; 1 }) { ...error handler... }

Replies are listed 'Best First'.
Re^3: How many different ways can Perl code fail?
by diotalevi (Canon) on Jan 14, 2009 at 09:10 UTC

      Guard seems interesting too. I haven't tested it but it's on my Perl todo list. Obviously not the same "niche" of application, but could be complementary (at least).

      cheers --stephan
Re^3: How many different ways can Perl code fail?
by wol (Hermit) on Jan 14, 2009 at 17:45 UTC
    Why is using $@ a bit unreliable?

    Update: Just found that the answer to this is covered by the documentation of Devel::EvalError. A quick read seems to suggest that the issue can only arise if there's a DESTROY method which uses eval (however indirectly) and doesn't localise $@.

    You'll have to decide whether that would be a problem for you...

    --
    use JAPH;
    print JAPH::asString();

      You'll have to decide whether that would be a problem for you...

      Not really. It's not like it's harder to handle the problem. I'd say it's even cleaner.

      eval { ... }; if ($@) { ... }

      vs

      eval { ...; 1 } or ...;

      and

      my $x = eval { ... }; if ($@) { ... }

      vs

      my ($x) = eval { ... } or ...;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found