Practice mode C#

When does a finally block execute in C#?

Correct answer B. After the try block and any catch, whether or not an exception occurred, even after return

Explanation

The finally block runs when control leaves the try statement by any route: normal completion, a return or break, or an exception, caught or propagating. That makes it the place to release resources such as files or locks. It may not run if the process is terminated abruptly, for example through Environment.FailFast or a stack overflow.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.