git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Only a message at the highest exception


I have a tkinter program where I have a function generate_report which
in a try block calls the function append_row. This function has also a
try block. When they get an exception they give message. But when
append_row has already given a message then generate_report should
not. To implement this I use the following class:
    class AlreadyHandledException(Exception):
        pass

Then in append_row I have:
    except Exception as err:
        messagebox.showerror(error_str,
                             error_append + '\n\n\n\n' + str(err))
        raise AlreadyHandledException()

And in generate_report I have:
    except Exception as err:
        if type(err).__name__ != "AlreadyHandledException":
            messagebox.showerror(error_str,
                                 error_generate + '\n\n\n\n' + str(err))
        progress.pack_forget()

Is this an acceptable way, or should I do it differently?

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