Will code in finally run after a redirect?

后端 未结 10 1313
别跟我提以往
别跟我提以往 2021-01-02 11:08

Take for example the following code:

   try
   {
      Response.Redirect(someurl);
    }
    finally
    {
       // Will this code run?
    }
10条回答
  •  走了就别回头了
    2021-01-02 11:53

    Why do you not just try it?

    finally always runs, except in these extreme scenarios:

    • Total application crash, or application termination (e.g. FailFast())
    • A limited number of serious exceptions
    • Threads getting terminated (eg. Thread.Abort())
    • Hardware failure (e.g. machine losing power)
    • Infinite loop inside the try-block (which ultimately results in application termination)

提交回复
热议问题