added try and exception to deal with file