[Tutor] Exceptions and wotnot

Glen Wheeler wheelege@hotmail.com
Wed, 20 Feb 2002 21:25:59 +1100


  Hey guys,

  My current project is a matrix study tool for uni students - with a GUI
wrapper written in tkinter.
  When there is an error, I use code like this :- (copy and pasted from a
class method in the wrapper)

        rinput = self.inputbox.get("@0,0", END)
        try:
            self.matrix = gmatrix.Matrix(rinput)
        except Exception:
            popupmsg('Error creating Matrix.  Check your formatting and try
again.\n  Traceback provided below for debugging, ask me (Glen) if you think
this error to be in error')

  The problem here is that the message lies - there isn't a traceback.  What
I'd like, and have been searching for a way to do, is this :

#snippo
        except Exception:
            popupmsg('Error creating Matrix.  Check your formatting and try
again.\n  Traceback provided below for debugging, ask me (Glen) if you think
this error to be in error'+str(Exception))

  Or something like it.  What I want is the traceback message python usually
produces - but I can't seem to find it anywhere.  I did think of going...

except ValueError:
    popupmsg(customizedvalueerrormsg)
excpet IndexError:
    popupmsg(customizedindexerrormsg)

  But it's not really what I want.  Surely there must be some way of getting
the traceback, out of the except Excpeption: construct.  I dir()ed the
exception using a bit of toy code but revealed no hints...
  Anywho I don't want to resort to Black Magic if possible, and am hoping
that my inexperience with exceptions is the only problem here.  Can anybody
help me out?

  Thanks guys,
  Glen