How would I add exception handling to this while loop?
I've can't seem to wrap my head around it.
I've tried... Try: except: but to no avail.
Specifically this is a file selector. When the user doesn't select a file or selects the wrong filetype I want to keep the program open, let them know of the error and allow them to select a different file, rather than having the program quit.
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
if event == ' Ok ':
# If OK, then need to add the filename to the list of files and also set as the last used filename
sg.user_settings_set_entry('-filenames-', list(set(sg.user_settings_get_entry('-filenames-', []) + [values['-FILENAME-'], ])))
sg.user_settings_set_entry('-last filename-', values['-FILENAME-'])
lastFile=values['-FILENAME-']
break
elif event == 'Clear History':
sg.user_settings_set_entry('-filenames-', [])
sg.user_settings_set_entry('-last filename-', '')
window['-FILENAME-'].update(values=[], value='')
window.close()