Java - Return statement and thrown exception using method inside catch block?

后端 未结 5 1767
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 15:40

I have following code using hibernate to throw a custom exception on error and I also want to close the session in this case, since the exception won\'t be catched unless receiv

5条回答
  •  深忆病人
    2021-01-21 16:08

    add finally to try-catch block finally { return null; } - If execution goes into try block and result is success it would return, so finally would never get executed. - If execution goes into catch block, the finally block gets executed after catch and would return null. Safe execution!

    Not correct answer!

提交回复
热议问题