The whole program revolves around using file_size on regular files. If the program sees a directory, it recursively descends down into it and calls file_size on all its entries.
The only thing we did to distinguish if we call file_size directly or if we need the recursion strategy was asking the is_directory predicate. This works well for directories that only contain regular files and directories.
As simple as our example program is, it would crash under the following conditions, because of unhandled exceptions:
- file_size only works on regular files and symbolic links. It throws an exception in any other case.
- Although file_size works on symbolic links, it still throws an exception if we call it on a broken symbolic link.
In order to make this example recipe program more mature, we need more defensive programming against the wrong type of files and handling of exceptions.