Added fix to catch file I/O exceptions so they can be handled via the return value.