문제

suppose that i have this code. if exception is InvalidData, do this will call finally to clean resources.

while(CanWork){
            try
            {
                 ....
            }
            catch (InvalidDataException e)
            {
                LogAction(false, e.Message, e.StackTrace);
                break;
            }
            catch (Exception e)
            {
                LogAction(false, e.Message, e.StackTrace);
            }
            finally
            {
                if (insta != null)
                {
                    insta.Disconnect();
                    insta.Dispose();
                    insta = null;
                }
            }
          }
도움이 되었습니까?

해결책

Yes it will, but not when it is about to leave the while, but just after the code in the try or catch is done executing.

다른 팁

Yes of course . finally block always gets executed . Please refer this link for more details

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top