相关疑难解决方法(0)

RMI和例外

我是使用RMI的新手,我对使用异常相对较新.

我希望能够在RMI上抛出异常(这可能吗?)

我有一个简单的服务器,为学生提供服务,我有删除方法,如果学生不存在,我想抛出一个自定义的StudentNotFoundException异常,它扩展了RemoteException(这是一件好事吗?)

任何建议或指导将不胜感激.

服务器接口方法

    /**
 * Delete a student on the server
 * 
 * @param id of the student
 * @throws RemoteException
 * @throws StudentNotFoundException when a student is not found in the system
 */
void removeStudent(int id) throws RemoteException, StudentNotFoundException;
Run Code Online (Sandbox Code Playgroud)

服务器方法实现

    @Override
public void removeStudent(int id) throws RemoteException, StudentNotFoundException
{
    Student student = studentList.remove(id);

    if (student == null)
    {
        throw new StudentNotFoundException("Student with id:" + id + " not found in the system");
    }
}
Run Code Online (Sandbox Code Playgroud)

客户端方法

    private void …
Run Code Online (Sandbox Code Playgroud)

java networking rmi

18
推荐指数
2
解决办法
1万
查看次数

链式异常的优点是什么?

我不明白在代码中使用链式异常的优点.

考虑来自java世界ResourceLoader示例,如果程序员知道遇到的可能性ResourceLoadException,为什么不捕获相同的异常而不是SQLException?另外,程序员可以捕获相同代码中的异常,而不是抛出新Throwable实例?

java exception-handling

12
推荐指数
4
解决办法
7763
查看次数

标签 统计

java ×2

exception-handling ×1

networking ×1

rmi ×1