[PyKDE] Trapping Exceptions

Kaleb Pederson kibab at icehouse.net
Tue May 27 01:05:01 BST 2003


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20030527/da822113/attachment.bin


More information about the PyQt mailing list