Why does this “finally” execute?

前端 未结 8 925
故里飘歌
故里飘歌 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:17

    Seems reasonable. A finally block is always run after either the try or the catch.

    Similarly

    try
    {
      // do something
      return;
    }
    finally
    {
      // do something else
    }
    

    will always run the finally block. EDIT - but see Eric's comments above.

提交回复
热议问题