tkinter shell problem

Russell E. Owen no at spam.invalid
Mon Nov 29 19:32:36 EST 2004


In article <mailman.6760.1101319149.5135.python-list at python.org>,
 "Philippe C. Martin" <philippecmartin at sbcglobal.net> wrote:

>Hi,
>
>I have the following problem:...
>If I trap (an exception), I do not get the stack dump that I which I would show.
>...
>If I don"t trap it, then my clean up code...does not get called...
>
>Yet Idle manages - any clue ?

Use the traceback module. For example:

            try:
                ...code to protect...
            except (SystemExit, KeyboardInterrupt):
                raise
            except Exception, e:
                traceback.print_exc(file=sys.stderr)
                ....code to handle exception...

if you are sure none of your code can raise error exceptions that 
inherit directly from Exception, you can simplify this to one except:
    except StandardError, e:
Unfortunately, some common modules (including Tkinter) raise exceptions 
that inherit from Exception, not StandardError.

-- Russell



More information about the Python-list mailing list