Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: eval {require module};?

by nobull (Friar)
on Apr 02, 2005 at 04:17 UTC ( [id://444350]=note: print w/replies, xml ) Need Help??


in reply to eval {require module};?

There are some situations (which I do not fully understand) where eval{} can trap an error and yet fail to set $@. However the return value will be undef.

So...

unless( eval { require module; 1 } ) { my $err = $@ || 'eval failed but did not return error'; # do something with $err }
Update: instert missing 1.

Replies are listed 'Best First'.
Re^2: eval {require module};?
by nobull (Friar) on Mar 17, 2006 at 17:27 UTC
    Many months later I now know how eval{} can fail and yet not set $@. It happens if a DESTROY method called during the stack-unwind also does an eval.
    use AtExit; eval { my $q = AtExit->new(sub{eval{}}); die "Oops\n"; }; print $@; # Prints nothing
      Which means you have to
      sub DESTROY{ local $@; eval{...} }
      if you want to use eval in DESTROY.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-16 20:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found