Re: How to capture an error with eval?

Discussion in 'Perl' started by patoban, Jul 9, 2004.

  1. patoban

    patoban Guest

    You could also use the 'do' command. There is a good example of error
    trapping using this in the perldoc

    Sean wrote:
    > I know "eval" and "if ($@)" is the equivalent of a try/catch in the C
    > programming world. My question is how to basically throw an error in
    > one perl script that can be caught by another? For example:
    >
    > ScriptA.pl:
    > -----------
    > typical perl code but when we are done, do we exit, die, or warn

    so
    > that ScriptB.pl can pick it up? EX:
    >
    > ScriptB.pl
    > -----------
    > eval {
    > `ScriptA.pl`
    > };
    >
    > if ($@) {
    > print "Errors occured: $@";
    > } else {
    > print "ScriptA ran perfectly!";
    > }
    >
    > The question is how to force an error/exit code in ScriptA so that
    > ScriptB picks it up? I keep getting everything ran ok because
    > technically ScriptA "can run"... it's just that I can't throw an

    error
    > up a level. Thanks all!
    >
    > Sean
    patoban, Jul 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean
    Replies:
    1
    Views:
    540
    Gunnar Hjalmarsson
    Jul 7, 2004
  2. Eric Newton
    Replies:
    3
    Views:
    9,358
    Brock Allen
    Apr 4, 2005
  3. Max
    Replies:
    7
    Views:
    9,088
  4. DataBinder.Eval and Eval.

    , Jun 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    524
    Karl Seguin [MVP]
    Jun 16, 2006
  5. Stephen Waits

    How to capture eval's stdout in 1.8?

    Stephen Waits, Mar 7, 2006, in forum: Ruby
    Replies:
    3
    Views:
    175
    Stephen Waits
    Mar 7, 2006
Loading...

Share This Page