Unreachable code, but reachable with an exception

前端 未结 9 1667
说谎
说谎 2020-12-28 11:22

This code is part of an application that reads from and writes to an ODBC connected database. It creates a record in the database and then checks if a record has been succes

9条回答
  •  别那么骄傲
    2020-12-28 11:48

    You have two return paths in your code, the second of which is unreachable because of the first. The last statement in your try block return returnValue == 1; provides your normal return, so you can never reach the return false; at the end of the method block.

    FWIW, order of exection related to the finally block is: the expression supplying the return value in the try block will be evaluated first, then the finally block will be executed, and then the calculated expression value will be returned (inside the try block).

    Regarding flow on exception... without a catch, the finally will be executed upon exception before the exception is then rethrown out of the method; there is no "return" path.

提交回复
热议问题