[wxPython-users] Exceptions

Raffaello Barella barbarossa.platz at gmail.com
Sun Mar 9 22:55:11 PDT 2008


2008/3/10, Raffaello Barella <barbarossa.platz at gmail.com>:
>
> Try with the following code in the call to App.MainLoop() (and in my
> applications it does catch the unhandled exceptions):


          try:
                    frame =3D  MainForm()
          except:
                    wx.Bell()
                    import traceback
                    import time
                    print traceback.format_exc()
                    mfile =3D AppName + '.log'
                    f =3D open(mfile, 'a')
                    f.write('\n')
                    tm =3D time.localtime()
                    print  str(time.strftime("%d-", tm)) +\
                    str(tm[1] - 1) +'-' + str(time.strftime("%Y %H:%M:%S",
tm)) + '\n'
                    traceback.print_exc(file =3D f)
                    f.close()
                    sys.exit(1)

This way, you get also an exception file you can read afterwards at you
leisure.

2008/3/10, Mark Erbaugh <mark at microenh.com>:
> >
> > Is there a place / way to trap unhandled exceptions in a wxPython
> > application.  At first I thought that I could put the call to
> > App.MainLoop() inside a try: except: block and catch the exception
> > there, but it seems that unhandled exceptions raised in my code never
> > make it there.
> >
> > My program uses psycopg to access a PostgreSQL database and if an
> > unexpected database error occurs, I'd like my program to display a
> > message with the error information from psycopg and exit.  I'm already
> > handling recoverable errors (integrity violations, etc).
> >
> > For example, one error that I want to abort from would be permission
> > problems. If somehow the user doesn't have the appropriate permissions
> > for an operation, I want to display the error so that someone can go
> > into Postgres and adjust permissions.
> >
> > Thanks,
> > Mark
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> > For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200803=
10/d195c5ec/attachment.htm


More information about the wxpython-users mailing list