What is the point of finally in a try catch/except finally statement

后端 未结 4 553
清酒与你
清酒与你 2021-01-30 15:33

I have used try-catch/except-finally variants in many languages for years, today someone asked me what is the point of finally and I couldn\'t answer.

Basically why wo

4条回答
  •  感情败类
    2021-01-30 16:14

    Finally make sure your code is executed even if you get an exception.

    The finally block is useful for cleaning up any resources allocated in the try block as well as running any code that must execute even if there is an exception

    http://msdn.microsoft.com/en-us/library/zwc8s4fz(v=vs.80).aspx

提交回复
热议问题