저는 RMI를 처음 사용하기 때문에 예외를 사용하는 것이 비교적 새롭습니다.RMI 및 예외
나는
내가 학생을 제공하는 간단한 서버를 (?이 가능하다) RMI를 통해 예외를 던질 수 있기를 원하고 나는 학생이 내가 원하는 존재하지 않는 경우 방법을 삭제해야 RemoteException을 확장하는 StudentNotFoundException의 사용자 정의 예외를 던집니다 (좋은 일 이니?)모든 조언이나 조언을 부탁드립니다.
서버 인터페이스 방법
/**
* 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;
서버 메소드 구현
@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");
}
}
클라이언트 방법
private void removeStudent(int id) throws RemoteException
{
try
{
server.removeStudent(id);
System.out.println("Removed student with id: " + id);
}
catch (StudentNotFoundException e)
{
System.out.println(e.getMessage());
}
}
StudentNotFoundException
package studentserver.common;
import java.rmi.RemoteException;
public class StudentNotFoundException extends RemoteException
{
private static final long serialVersionUID = 1L;
public StudentNotFoundException(String message)
{
super(message);
}
}
답장을 보내 주셔서 감사합니다. 이제 문제를 해결하고 RemoteException을 확장하는 것이 좋지 않다는 것을 깨달았습니다.
훗은, 그 질문은 잘 알고 보인다! –
는 실제로 게시하기 전에이 바라 보았다. 조언을 건배 - 난 내가 문제가 – Malachi