If you mean that some Perl function in module A (in say FileA.pm or main program) calls some sub, funcB() in Perl module B(in FileB.pm or even within main program module) and this funcB() does an exit(1)...There is nothing to be "done" about it, exit(x) returns a status code to the OS and the Perl program stops. Your funcA() will never see this exit(1) value.

It sounds to me like you should replace say "exit(1);" with die "some error message";. "die" prints an error message to STDERR and then the Perl program stops. If the "die" statement's string does not end in a \n, then Perl will report module and line number when "death occured". Normally this is of no interest to the user if the error message is good enough. But sounds like this tid-bit will help you debug a problem (extra info good for you).

The "normal" convention for a program to exit when it completes successfully is exit(0) or exit(with a non zero value) if program "bombed". That value (8 bits) is reported to the shell that invoked the program. I don't think that you want to mess around with starting a shell program that starts your Perl script and checks the return code.

Instead of exit(1), in Perl use: die "some error". Throwing exceptions has to do with OO stuff and OO is probably not what you have here in the legacy code. Do a search for the exit() lines and replace with 'die "error msg"' lines.


In reply to Re: Subroutine to indicate error condition by Marshall
in thread Subroutine to indicate error condition by kk2202

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.