Java return value (in try/catch clause)

后端 未结 6 416
生来不讨喜
生来不讨喜 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:16

    In Java (or any other C-like language) all control paths must return a value.

    If an exception is thrown inside the try then the return will not be executed and so you are not returning a value on all possible control paths.

    You have to either:

    1. add a return after the try-catch or
    2. add a return inside each catch or
    3. add a finally with a return.

提交回复
热议问题