Valor de retorno de Java (na cláusula try / catch)
todos. Eu tenho uma pergunta rookie sobre o valor de retorno em java. Aqui está meu código.
@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);
}
}
O Eclipse relata um erro "Este método deve retornar um resultado do tipo longo". No entanto, retornei o tid no bloco try; O eclipse sugere adicionar um valor de retorno após o bloco try / catch, o que quebraria a lógica. Você poderia por favor me dizer o que está errado aqui? Obrigado.