How to return a value from try, catch, and finally?

前端 未结 4 914
情歌与酒
情歌与酒 2020-12-18 18:30

So when I do a code of blocks inside a try{}, and I try to return a value, it tells me

no return values

4条回答
  •  伪装坚强ぢ
    2020-12-18 19:33

    The problem is what happens when you get NumberFormatexception thrown? You print it and return nothing.

    Note: You don't need to catch and throw an Exception back. Usually it is done to wrap it or print stack trace and ignore for example.

    catch(RangeException e) {
         throw e;
    }
    

提交回复
热议问题