In C# will the Finally block be executed in a try, catch, finally if an unhandled exception is thrown? [duplicate]

finally is executed most of the time. It’s almost all cases. For instance, if an async exception (like StackOverflowException, OutOfMemoryException, ThreadAbortException) is thrown on the thread, finally execution is not guaranteed. This is why constrained execution regions exist for writing highly reliable code. For interview purposes, I expect the answer to this question to be … Read more

return eats exception

The exception disappears when you use return inside a finally clause. .. Is that documented anywhere? It is: If finally is present, it specifies a ‘cleanup’ handler. The try clause is executed, including any except and else clauses. If an exception occurs in any of the clauses and is not handled, the exception is temporarily … Read more

Why do we use finally blocks? [duplicate]

What happens if an exception you’re not handling gets thrown? (I hope you’re not catching Throwable…) What happens if you return from inside the try block? What happens if the catch block throws an exception? A finally block makes sure that however you exit that block (modulo a few ways of aborting the whole process … Read more

C++, __try and try/catch/finally

On Windows, exceptions are supported at the operating system level. Called Structured Exception Handling (SEH), they are the rough equivalent to Unix signals. Compilers that generate code for Windows typically take advantage of this, they use the SEH infrastructure to implement C++ exceptions. In keeping with the C++ standard, the throw and catch keywords only … Read more

Does a finally block always run?

from the Sun Tutorials Note: If the JVM exits while the try or catch code is being executed, then the finally block may not execute. Likewise, if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues. I don’t … Read more

Does C++ support ‘finally’ blocks? (And what’s this ‘RAII’ I keep hearing about?)

No, C++ does not support ‘finally’ blocks. The reason is that C++ instead supports RAII: “Resource Acquisition Is Initialization” — a poor name† for a really useful concept. The idea is that an object’s destructor is responsible for freeing resources. When the object has automatic storage duration, the object’s destructor will be called when the … Read more