Raise an error with a python object

John (J5) Palmieri johnp at redhat.com
Fri May 12 09:57:39 PDT 2006


You can just raise an error.  It will be propagated over the bus.

On Fri, 2006-05-12 at 15:56 +0200, Luigi Paioro wrote:
> Hi!
> 
> I have an object put on the bus which has a method that can raise 
> errors. How can I handle such situation? I've read that I have to use a 
> dbus.Error object, can anybody send me an example?
> 
> For example, suppose I have something like this:
> 
> #!/usr/bin/python
> 
> import gobject
> import dbus
> 
> import dbus.service
> 
> if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
>      import dbus.glib
> 
> class HelloWorldObject(dbus.service.Object):
>      def __init__(self, bus_name, 
> object_path='/org/freedesktop/HelloWorldObject'):
>          dbus.service.Object.__init__(self, bus_name, object_path)
> 
>      @dbus.service.method('org.freedesktop.HelloWorldIFace')
>      def hello(self, flag):
> 	if not flag:
> 	    # TODO: RAISE AN ERROR
>          return 'Hello from the HelloWorldObject'
> 
> 
> session_bus = dbus.SessionBus()
> bus_name = dbus.service.BusName('org.freedesktop.HelloWorld', 
> bus=session_bus)
> object = HelloWorldObject(bus_name)
> 
> mainloop = gobject.MainLoop()
> mainloop.run()
> 
> 
> How can I fix it?
> 
> Thanks in advance.
> 
> Luigi
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus
-- 



More information about the dbus mailing list