Java return value (in try/catch clause)

后端 未结 6 364
生来不讨喜
生来不讨喜 2021-01-12 17:25

everyone. I have a rookie question about the returning value in java. Here\'s my code.

@Override
public long addDrugTreatment(long id, String diagnosis, Stri         


        
6条回答
  •  再見小時候
    2021-01-12 18:04

    Let's imagine a JMSException was thrown:

    @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();
            //JMS thrown above. No code from here gets executed
        } catch (PatientExn e) {
            throw new PatientNotFoundExn(e.toString());
        } catch (JMSException e) {
            logger.severe("JMS Error: " + e);
        }
    }
    

    In the above if a JMSException is thrown no part of the code returns a long.

提交回复
热议问题