Why does this “finally” execute?

前端 未结 8 919
故里飘歌
故里飘歌 2020-12-14 19:02

If you run the code below it actually executes the finally after every call to the goto:

    int i = 0;
Found:
    i++;
    try
    {
        throw new Exc         


        
8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 19:18

    The gist of the answers given - that when control leaves the protected region via any means, whether "return", "goto", "break", "continue" or "throw", the "finally" is executed - is correct. However, I note that almost every answer says something like "the finally block always runs". The finally block does NOT always run. There are many situations in which the finally block does not run.

    Who wants to try to list them all?

提交回复
热议问题