<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd--> <html xmlns="http://www.w3.org/1999/xhtml" > <head><title>DBusExecutionException</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> <meta name="originator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> <!-- xhtml,2,html --> <meta name="src" content="dbus-java.tex" /> <meta name="date" content="2014-10-16 21:40:00" /> <link rel="stylesheet" type="text/css" href="dbus-java.css" /> </head><body > <!--l. 374--><div class="crosslinks"><p class="noindent">[<a href="dbus-javase4.html" >prev</a>] [<a href="dbus-javase4.html#taildbus-javase4.html" >prev-tail</a>] [<a href="dbus-javase2.html#taildbus-javase5.html">tail</a>] [<a href="dbus-java.html# " >up</a>] </p></div> <h3 class="sectionHead"><span class="titlemark">5 </span> <a id="x20-180005"></a>DBusExecutionException</h3> <!--l. 376--><p class="noindent" >If you wish to report an error condition in a method call you can throw an instance of <span class="cmtt-12">DBusExecutionException</span><span class="footnote-mark"><a href="dbus-java21.html#fn12x0"><sup class="textsuperscript">12</sup></a></span><a id="x20-18001f12"></a> . 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 <a href="#x20-180026">6<!--tex4ht:ref: fig:exceptiondef --></a> and then throw it in your method as in figure <a href="#x20-180037">7<!--tex4ht:ref: fig:exceptioncall --></a>. </p> <hr class="figure" /><div class="figure" > <a id="x20-180026"></a> <div class="center" > <!--l. 386--><p class="noindent" > </p> <div class="verbatim" id="verbatim-12"> package org.freedesktop.DBus.Error;  <br />import org.freedesktop.dbus.exceptions.DBusExecutionException;  <br />  <br />public class UnknownMethod extends DBusExecutionException  <br />{  <br />   public UnknownMethod(String message)  <br />   {  <br />      super(message);  <br />   }  <br />} </div> <!--l. 398--><p class="nopar" ></p></div> <br /> <div class="caption" ><span class="id">Figure 6: </span><span class="content">An Exception</span></div><!--tex4ht:label?: x20-180026 --> </div><hr class="endfigure" /> <hr class="figure" /><div class="figure" > <a id="x20-180037"></a> <div class="center" > <!--l. 405--><p class="noindent" > </p> <div class="verbatim" id="verbatim-13"> ...  <br />public void throwme() throws org.freedesktop.DBus.Error.UnknownMethod  <br />{  <br />   throw new org.freedesktop.DBus.Error.UnknownMethod("hi");  <br />}  <br />... </div> <!--l. 413--><p class="nopar" ></p></div> <br /> <div class="caption" ><span class="id">Figure 7: </span><span class="content">Throwing An Exception</span></div><!--tex4ht:label?: x20-180037 --> </div><hr class="endfigure" /> <!--l. 419--><p class="indent" > If you are calling a remote method and you want to handle such an error you can simply catch the exception as in figure <a href="#x20-180048">8<!--tex4ht:ref: fig:exceptioncatch --></a>. </p> <hr class="figure" /><div class="figure" > <a id="x20-180048"></a> <div class="center" > <!--l. 423--><p class="noindent" > </p> <div class="verbatim" id="verbatim-14"> ...  <br />try {  <br />   remote.throwme();  <br />} catch (org.freedesktop.DBus.Error.UnknownMethod UM) {  <br />   ...  <br />}  <br />... </div> <!--l. 432--><p class="nopar" ></p></div> <br /> <div class="caption" ><span class="id">Figure 8: </span><span class="content">Catching An Exception</span></div><!--tex4ht:label?: x20-180048 --> </div><hr class="endfigure" /> <!--l. 438--><div class="crosslinks"><p class="noindent">[<a href="dbus-javase4.html" >prev</a>] [<a href="dbus-javase4.html#taildbus-javase4.html" >prev-tail</a>] [<a href="dbus-javase5.html" >front</a>] [<a href="dbus-java.html# " >up</a>] </p></div> <!--l. 438--><p class="indent" > <a id="taildbus-javase5.html"></a> </p> </body></html>