Exceptions quit mainloop.

Heston James - Cold Beans heston.james at coldbeans.co.uk
Thu Sep 18 04:29:42 PDT 2008


Hello Guys,

 

I have a situation which I've seen arise recently within an application
built in python using the dbus gobject mainloop whereby when uncaught
exceptions occur within the application it doesn't crash gracefully and I
get sprawls or logging data spat back to the command line and the
application continues to run.

 

I'm looking for a sure fire way that any uncaught exceptions which occur in
the application will cause the mainloop to quit and the application to stop
running properly, I can then have the system relaunch it.

 

I'm thinking perhaps something like this might work:

 

        # Attempt to run the mainloop.

        try:

            # Call for the mainloop to run.

            main_loop.run()

        # Catch any exceptions which may occur.

        except Exception, e:

            # An exception occurred within the application.

            # Log the exception which has occurred.

            self.__logger.critical("FATAL EXCEPTION OCCURRED: %s" % str(e))

            # Quit the mainloop.

            main_loop.quit()

 

This I would have thought will catch any exceptions which aren't caught at a
lower level, log what has happened and then close the application down.

 

Is this the correct way to handle this? I'd a really appreciate your advice
and experience.

 

Cheers all,

 

Heston

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20080918/5c208e4c/attachment.html 


More information about the dbus mailing list