मैं आरएमआई का उपयोग करने के लिए नया हूं और मैं अपवादों का उपयोग करने के लिए अपेक्षाकृत नया हूं।आरएमआई और अपवाद
मैं RMI से अधिक एक अपवाद फेंकने के लिए सक्षम होना चाहते हैं (संभव है?)
मैं एक साधारण सर्वर जो छात्रों को पेश करता है और मैं विधि है जो अगर छात्र मौजूद नहीं है मैं चाहता हूँ हटाना है 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);
}
}
आपके उत्तर के लिए धन्यवाद अब मैंने अपनी समस्या को ठीक करने में कामयाब रहा है और महसूस किया है कि रिमोटएक्सप्शन को विस्तारित करना बुरा विचार था।
हे, यह प्रश्न परिचित लग रहा है! –
मैंने वास्तव में पोस्ट करने से पहले इसे देखा। सलाह के लिए चीयर्स - मुझे लगता है कि मुझे समस्या हल हो गई है – Malachi