Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone I am trying to write a simple script spawning a batch file from a perl script and I would like to return errorlevel from that batch. I am trying to use the error.pm and running into some syntax errors. Here is what I have. Perhaps another set of eyes could help.
use Error qw(:try); try { `$create_script $input`; #code that might thrown an exception; return; } catch Error with { my $error_handler = shift; # Get hold of the exception object } exit;
Thank you in advance, help is appreciated.

2005-02-16 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: error handling
by TedYoung (Deacon) on Feb 16, 2005 at 15:43 UTC

    What is the syntax error?

    Make sure you put a semicolon (;) after your catch Error with {} statement. This is a statement, not a block construct like if and while.

    use Error qw(:try); try { `$create_script $input`; #code that might thrown an exception; return; } catch Error with { my $error_handler = shift; # Get hold of the exception object }; # <-- Semicolon exit;

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Re: error handling
by RazorbladeBidet (Friar) on Feb 16, 2005 at 15:39 UTC
    Try putting your code into <code> blocks... like this:

    use Error qw(:try); try { `$create_script $input`; #code that might thrown an exception; return; } catch Error with { my $error_handler = shift; # Get hold of the exception object } exit;


    As it is, I don't see any "syntax" errors with that. However:

    1) There is no need to "return" from the try block
    2) No output will be captured.

    If you want the actual output from the script captured, do this:
    my $output = `$create_script $input`

    If you want the return code, you need to check out the system call.
Re: error handling
by Anonymous Monk on Feb 16, 2005 at 18:02 UTC
    You guys have been great!!! Looks like the system call works just fine.