每个人。我有一个关于java中返回值的菜鸟问题。这是我的代码。
@Override
public long addDrugTreatment(long id, String diagnosis, String drug,
float dosage) throws PatientNotFoundExn {
try {
Patient patient = patientDAO.getPatientByDbId(id);
long tid = patient.addDrugTreatment(diagnosis, drug, dosage);
Connection treatmentConn = treatmentConnFactory.createConnection();
Session session = treatmentConn.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(treatmentTopic);
TreatmentDto treatment = null;
ObjectMessage message = session.createObjectMessage();
message.setObject(treatment);
producer.send(message);
return tid;
} catch (PatientExn e) {
throw new PatientNotFoundExn(e.toString());
} catch (JMSException e) {
logger.severe("JMS Error: " + e);
}
}
Eclipse 报告“此方法必须返回 long 类型的结果”错误。然而,我确实在 try 块中返回了 tid;eclipse 建议在 try/catch 块之后添加一个返回值,这会破坏逻辑。你能告诉我这里有什么问题吗?谢谢。