RMIを初めて使用していて、例外を使用するのが比較的新しいです。RMIと例外
私は(これは可能ですか?)RMI上の例外をスローすることができるようにしたい
私は、学生を提供単純なサーバーを持っていると私は、学生が存在しない場合、私がしたいdeleteメソッドを持っています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