added exception before reading/writing file