Versions Compared

Key

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

Many functions return useful values whether or not the function has side effects. In most cases, this value is used to signify whether the function successfully completed its task or if some error occurred. Other times, the value is the result of some computation and is an integral part of the function's API.

Since Because a return value often contains important information about possible errors, it should always be checked; otherwise, the cast should be made explicit to signify programmer intent.

...

It makes sure the variable containing the file name is properly defined, but it does nothing else to catch errors. Consequently, any error, such as the file not existing, being readableunreadable, or containing too much data to read into memory will cause the program to abort.

Compliant Solution

This compliant colution solution does the same thing , but provides useful error messages if anything goes wrong.

...

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.

...

EXP32-EX2: 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, then functions it redefined may be safely ignored.

...