Pregunta

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;
                }
            }
          }
¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top