Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If any error occurs, the program calls the croak() function, passing it a string that includes both the source file being opened and the $! variable, which contains a system error string based on the value of errno, which is set to a useful value when the open(2) or close(2) functions fail.

Exceptions

EXP32-:EX0: If the return value is inconsequential or if any errors can be safely ignored, such as for functions called because of their side effects, the function's return value may be silently discarded.

EXP32-:EX1: The autodie module is designed to replace functions that return a value indicating failure with functions that throw an exception on failure. When autodie is in use, any functions it redefines may be safely ignored.

Code Block
bgColor#ccccff
langperl
use autodie;

my $source;
open(SOURCE, "<", $source);
@lines = (<SOURCE>);
close(SOURCE);

EXP32-:EX2: Functions that send data to standard output or standard error need not have their return values checked. This includes print and printf, but only if their filehandle argument is not supplied, or is explicitly set to *STDOUT or *STDERR. If they send their output to any other filehandle, their return value must be checked.

EXP32:EX3: When inside error-handling code, function calls that are used to release resources, such as close() need not have their return values checked. Any code that falls under this exception should be explicitly documented as such.

Risk Assessment

Failure to handle error codes or other values returned by functions can lead to incorrect program flow and violations of data integrity.

...