远程方法还可抛出您所需要的任何其他例外,但至少必须抛出RemoteException,这样您才能处理只会在分布式系统中发生的错误状态。该接口本身支持两个方法:getPolicy (返回一个实现政策接口的对象),和submitReport (提交一个完成的开支请求,并在报告无论因何种原因使表格出现错误时,抛出一个例外)。 政策接口本身可声明一种使客户机知道能否在开支报告中添加一个项目的方法: public interface Policy { void checkValid (Expenseentry entry) throws PolicyViolationException; } 假如该项目有效--即符合当前政策,则该方法可正常返回。否则就会抛出一个描述该错误的例外。政策接口是本地的(而非远程的),所以将通过本机对象在客户机上执行--在客户机的虚拟机上,而非整个网络上运行的对象。客户机可能运行下列程序: Policy curPolicy = server.getPolicy(); start a new expense report show the GUI to the user while (user keeps adding entries) { try { curPolicy.checkValid(entry); // throws exception if not OK add the entry to the expense report } catch (PolicyViolationException e) { show the error to the user } } server.submitReport(report);