We've seen many questions about try-catch-finally
and try-finally
constructions on this forum.
The number of answers increases the number of questions, so I have few too.
Here's a link into Microsoft explanation try-finally construction. I've already read it!
In the following article writes:
Within a handled exception, the associated finally block is guaranteed to be run. However, if the exception is unhandled, execution of the finally block is dependent on how the exception unwind operation is triggered. That, in turn, is dependent on how your computer is set up.
Am i correctly understand that in
try-catch-finally
constructionfinally
will always be executed? (ExcludingEnvironment.FastFail()
)I've read about
StackOverFlowException
(thatfinally
block isn't executed in this occasion) on this forum, but when Ithrow
it, thefinally
block is executed. So What's aboutStackOverFlowException
?Why
finally
block is not called?(In the code below)?For which cases we generally use
try-finally
?From what PC setting the
finally
block is depended?
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
throw new Exception();
}
finally
{
Console.WriteLine("finally");
Console.ReadKey();
}
}
}
}