all. I have a question about return value in java. Here is my code.
@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 reports the error "This method should return a result of type long." However, I returned tid to the try block; eclipse suggests adding a return value after the try / catch block, which breaks the logic. Could you tell me what is wrong here? Thanks.
source share