5 DBusExecutionException

If you wish to report an error condition in a method call you can throw an instance of DBusExecutionException12 . This will be sent back to the caller as an error message, and the error name is taken from the class name of the exception. For example, if you wanted to report an unknown method you would define an exception as in figure 6 and then throw it in your method as in figure 7.


package org.freedesktop.DBus.Error;  
import org.freedesktop.dbus.exceptions.DBusExecutionException;  
 
public class UnknownMethod extends DBusExecutionException  
{  
   public UnknownMethod(String message)  
   {  
      super(message);  
   }  
}


Figure 6: An Exception


...  
public void throwme() throws org.freedesktop.DBus.Error.UnknownMethod  
{  
   throw new org.freedesktop.DBus.Error.UnknownMethod("hi");  
}  
...


Figure 7: Throwing An Exception

If you are calling a remote method and you want to handle such an error you can simply catch the exception as in figure 8.


...  
try {  
   remote.throwme();  
} catch (org.freedesktop.DBus.Error.UnknownMethod UM) {  
   ...  
}  
...


Figure 8: Catching An Exception