Added better error checking

Added try except during opening file.