The finally block does not always execute in try finally

梦想与她 提交于 2020-02-28 16:07:50

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!");
            }
        }

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!