The code in the finally block will execute before the method exits,
even if exceptions are thrown and regardless of if those exceptions
are caught or not.
In your second method, z will not execute if an exception that is not
handled in the catch block is thrown.
Very often, try -- finally is used without a catch block. C# even has
special
shortcut for that, the using statement.
- Magnus
"Joe Thompson" <Jo*********@di scussions.micro soft.com> wrote in message
news:6D******** *************** ***********@mic rosoft.com...
Hi,
This is probably a simple question but I'm curious. What is the purpose
of
the "finally" statement? There must be a good reason to use it that I'm
just
not getting...
How is this:
method1
{
try
{
x;
}
catch
{
y;
}
finally
{
z;
}
}
different than:
method1
{
try
{
x;
}
catch
{
y;
}
z;
}
Thank you,
Joe