A finally block does not always xecute. The code in the try block could go into an infinite loop, the exception could rigger a “fail fast” (which takes the process down without running any finally locks), or someone could pull the power cord out of the wall.
eg.
static void TryFinallyDemo() { try { while(true) { Console.WriteLine(DateTime.Now.ToString("yyyyMMddHHmmssffff")); } } finally { Console.WriteLine("Finally block does not always execute!"); } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/67171.html
標籤:C#
上一篇:C#中實作檔案拖放打開的方法
