Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Perl exception - multiple statement

by kennethk (Abbot)
on Jul 20, 2009 at 16:30 UTC ( [id://781682]=note: print w/replies, xml ) Need Help??


in reply to Perl exception - multiple statement

In order to escape from the eval block, you need to tell Perl something unexpected has occurred. This usually done with die, where you should check $? after each system command, a la:

eval { system("cp xyz.dat abc.dat"); die "$?\n" if ($?); system("cp xyz.dat2 abc.dat2"); die "$?\n" if ($?); }; if ($@) { print "Error occured: $@\n"; }

Please note the difference in reliable scoping between $? and $@ - as noted in Error Indicators.

Update: As JavaFan notes, this does not capture the actual error messages, only the error codes returned from system (as per your OP). If you want to handle the actual error messages, you'll need to capture STDERR, as per 781684.

Replies are listed 'Best First'.
Re^2: Perl exception - multiple statement
by JavaFan (Canon) on Jul 20, 2009 at 16:42 UTC
    Note that just "solution" doesn't give you the actual error message. Just information about the exit value, the signal that terminated the child, and whether core was dumped.

Log In?
Username:
Password:

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

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

    No recent polls found