Exception is swallowed by finally

前端 未结 7 1912
攒了一身酷
攒了一身酷 2020-12-08 23:54
static int retIntExc() throws Exception{
    int result = 1;
    try {
        result = 2;
        throw new IOException(\"Exception rised.\");
    } catch (ArrayInd         


        
7条回答
  •  我在风中等你
    2020-12-09 00:19

    This is because you issue a return statement before the exception is passed trough and thus a valid value is returned. You cannot both return a value and throw an exception.

    Removing the finally block around the return will give the behaviour you want.

提交回复
热议问题