What type of error is it

Cecil Westerhof Cecil at decebal.nl
Wed Jun 26 08:06:36 EDT 2019


Cecil Westerhof <Cecil at decebal.nl> writes:

> I am writing a GUI program with tkinter. One function I have is:
> def select_dir():
>     try:
>         directory = filedialog.askdirectory()
>         if directory == '':
>             messagebox.showinfo(info_str, canceled_report)
>             return
>         chdir(directory)
>         filepathArr = sorted(glob(regex))
>         if len(filepathArr) == 0:
>             messagebox.showwarning(warning_str, nofiles_str)
>             return
>         generate_report(filepathArr)
>     except:
>        messagebox.showerror(error_str, error_select_str)
>        raise
>
> I use the raise to see what the exception was. That works, because
> tkinter takes over again.
> This works for me when I run it from the command-line, but it has to
> become a stand-alone executable. Is there a way to find out what the
> cause of the exception was, so I can put it in the error message?

Found it. I just need to change the last three lines to:
    except Exception as err:
       messagebox.showerror(error_str,
                            error_select_str + '\n\n\n\n' + str(err))

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



More information about the Python-list mailing list