Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This seems like such a fundamental question, but even though I've written thousands of lines of working Perl, I am quite puzzled by this issue.

I am writting a comprehensive set of scripts for building some software. Two features are that it must log comprehensively to a file anything of use in addition to providing some informative and progress messages to stdout; and, it must be very comprehensive in its error handling.

What has me puzzled is how one captures error information for many of the basic functions within Perl, and more specifically file related functions such as open, close, copy, unlink as a few examples. The common practice for these is to code up:

open(...) or die ".... $!"
My script needs to be more sophisticated in what it does in the error case than doing a simple die. I am guessing that I can put any code I need in the or case, but I have not seen any examples. Also, is the $! just a textual error message? I am thinking something like:
open (...) or { $errormsg = $!; $status = -1 }
or something similar would do the trick?

Anyone out there have any experience in doing more complete and rigorous error handling in Perl?

In reply to comprehensive error handling by mgibian

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (6)
    As of 2020-11-26 10:02 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found