[python] Nicer exceptions

Vincent Génieux vincent.genieux at enensys.com
Tue Jun 3 09:42:34 PDT 2008


René 'Necoro' Neumann wrote:
> Hi,
>
> it is currently not really possible to pass data via Exceptions from the
>  server to the client, as the traceback _plus_ additional data is
> mangled into one string.
>
> This leads to things like:
> name, data = str(e).split("\n")[-2].split(": ")[1:]
>
> which is likely to break somewhere. (and is ugly like hell).
>
> Would there be the chance, that DBusExceptions provide a "traceback" and
> a "message" member, so that the traceback does not get included into the
> message anymore?
>
> Additionally, this is done already in the server - thus the string magic
> above will only work, if the server is using python-dbus. I guess that
> the exceptions look different, if other dbus bindings are used.
>
> Regards,
> Necoro

Hello,

I have a similar problem here:
I would like my service object to be able to returns its own Error
messsages.
Is it possible ?


class Example(dbus.service.Object):
    def __init__(self, object_path):
        dbus.service.Object.__init__(self, dbus.SessionBus(), path)


    @dbus.service.method(dbus_interface='com.example.Sample',
                         in_signature='ii', out_signature='i')
    def div(self, a, b):
        if b != 0:
            return a / b
        else:
            raise MyDBusError(name="myServiceError", "second parameter
cannot be zero")


--
vincent.


More information about the dbus mailing list