none
Finally clause RRS feed

  • Question

  • Hi,

    I want to know about 'Finally' clause.

    I have a function in which try, catch, finally blocks are there. And this function is running in a background thread.

    private void background()
    
    {
    
    try{}
    
    catch{}
    
    finally{}
    
    }
    
    private void btn_click()
    
    {
    
    backgroundthread.abort()
    
    .
    
    .
    
    .
    
    .
    
    }


    And I have a button click event in which I kill this background thread. At the time I click on the button the line 5 in try block is being executed in the background thread.

    Will the finally be called before my main thread event handler specific code block is executed? 

    what all situations that finally be called... Examples : if you close the application etc...




    Tuesday, February 19, 2013 12:04 PM

Answers

  • "Will the finally be called before my main thread event handler specific code block is executed?"

    What "main thread event handler"?

    "what all situations that finally be called... Examples : if you close the application etc..."

    The finally block will be executed if the try block is executed until the end or if an exception is thrown inside that try block, nothing more, nothing less. The finally block won't be executed if the application is closed or if an exception is thrown anywhere outside the try block.

    Tuesday, February 19, 2013 12:31 PM
    Moderator