first cut of hal service description file

Havoc Pennington hp at redhat.com
Thu Mar 31 15:56:52 PST 2005


On Fri, 2005-04-01 at 00:23 +0200, Tako Schotanus wrote:
> Regardless of the fact if the exception is explicitly defined or not it 
> is important to be able to figure out which exception has been thrown so 
> that the caller can decide to handle it or to throw it up the chain. In 
> what way will that be made possible? Because just one generic 
> DBusException seems pretty useless. Or it will force you to write 
> old-style code where return-values tell you if the method-call did its 
> job or not (eg. did DeleteFile actually delete the file) and the 
> exception will only tell you that something worse happened (eg. the bus 
> went off-line, connection failure).

Just have subclasses, right? So the method signature is:

 Foo() throws SuperClass;

But you have:

 class SubClass1 extends SuperClass;
 class SubClass2 extends SuperClass;

Then you can catch(SubClass1) if you want... isn't this allowed in most
languages?

It doesn't really work though, since there's no "IDL" to contain
SubClass1 - so I think in practice the answer is:

 class DBusException {
   boolean hasName(String name);
 }

and the code is:

 catch (DBusException e) {
   if (e.hasName("org.freedesktop.Foo"))
     // handle
   else
     throw e;
 }

Kind of ugly, but it's the price of staying dynamic rather than static.

Havoc




More information about the dbus mailing list