[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] Trapping Exceptions
From:       Kaleb Pederson <kibab () icehouse ! net>
Date:       2003-05-26 23:03:40
[Download RAW message or body]

On Monday 26 May 2003 08:37, Yannick Gingras wrote:
> Hi, I'd like to trap exceptions raised by the QApplication.
>
> Is there a way to override the default behaviour of QApplication to
> dump the trace back to stderr by a QMessageBox ?

You can easily do it, just adapt the following to your situtation.  This is 
actually something that Greg Fortune (also on the list) wrote for our 
projects:

def handle_error(t, val, tb):
    import traceback
    import string
    msg =  '-----------------------------------------------------\n'
    msg += 'Traceback:\n'
    msg += string.join(traceback.format_tb(tb), '') + '\n'
    msg += '%s: %s\n' % (str(t), str(val))
    msg += '-----------------------------------------------------\n'
    print msg

    import ...backend.db as db
    if(db.is_connected()):
        import ...backend.Error as Error
        e = Error.Error()
        e.set_error(msg)
        e.submit()

sys.excepthook = handle_error

Of course, make sure qt fully works before you uproot sys.excepthook.

--Kaleb

[Attachment #3 (application/pgp-signature)]
_______________________________________________
PyKDE mailing list    PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic