Ok in that case, which ones are considered to be system calls?

Good question, I thought there was a full list in the perldocs, but I can't find it - most of it is documented in perlfunc, but print() also sets $! on error (and returns false), which isn't documented there, so there might be omissions.

In general, errors from child processes in system() and `` are set in $? (though they set $! if the exec() fails), eval() errors are set in $@ and system errors that are not handled otherwise in the interpreter (not promoted to exceptions or worked around) set their errors in $! - these include file and pipe errors from print(), open(), read(), close() etc. All these functions return some value to indicate success/failure, and you should only read $! on failure.

If you want to be sure, "Programming Perl 3rd edition" (the Camel book) has a list of all built-in functions and and also notes which ones set $!.

Also, you might want to take a look at the standard (since perl 5.6) Fatal module. With it you can force an exception on functions that return false on error if you don't explicitly test for them (sadly, it doesn't work with system() and other functions that return true on error):

from the docs:

use Fatal qw/:void open close/; # properly checked, so no exception raised on error if(open(FH, "< /bogotic") { warn "bogo file, dude: $!"; } # not checked, so error raises an exception close FH;

update: just to answer your other question: running out of memory in the interpreter will throw an exception which is untrappable by default (so your code should die on the line causing the exception). In theory, it's possible to catch this exception, but your code probably isn't trying to. See the $^M entry in perlvar.


In reply to Re^6: Error: Not enough space by Joost
in thread Error: Not enough space by jhazra

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.