6
Reply

As we all know that if there is try-catch-finally or try-finally block then finally block is always executed. But this is not the case every time. There are scenarios when even finally block dos not execute. What are those scenarios?

Brij Mishra

Brij Mishra

11y
2.8k
0
Reply

    System.exit();

    try Environment.exit(0) inside a try block...

    when page state is changed inside try block.

    when page state is changed inside try block.

    The finally block will not be executed when there's a StackOverflowException for similar kind of c# interview questions refer this link c# interview questions

    As mentioned in the question, there are few scenarios when even finally block does not get executed. Finally block does not execute when the following type of exception occurs
    •ExecutionEngineException
    •StackOverflowException
    ExecutionEngineException occurs when there is some error in Common Language Runtime. A case could be if there is some exception while executing garbage collection. This exception also occurs if Environment.FailFast() fired.
    StackOverflowException occurs when there is no space available in stack to execute further.