K
K Viltersten
I feel a bit dense because i can't figureout the point with the keyword
finally.According to the MSDN, the followingexample shows the usage of it.//
try_catch_finally.cs
using System;
public class EHClass
{
static void Main()
{
try
{
Console.WriteLine("Executing the try statement.");
throw new NullReferenceException();
}
catch (NullReferenceException e)
{
Console.WriteLine("{0} Caught exception #1.", e);
}
catch
{
Console.WriteLine("Caught exception #2.");
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}
The way i figure, finally gets called both when there's
been an error and when there hasn't been one. So
why not go:
try {...}
catch(Exception) {}
doStuff();
instead of:
try {...}
catch(Exception) {}
finally {doStuff();}
?
finally.According to the MSDN, the followingexample shows the usage of it.//
try_catch_finally.cs
using System;
public class EHClass
{
static void Main()
{
try
{
Console.WriteLine("Executing the try statement.");
throw new NullReferenceException();
}
catch (NullReferenceException e)
{
Console.WriteLine("{0} Caught exception #1.", e);
}
catch
{
Console.WriteLine("Caught exception #2.");
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}
The way i figure, finally gets called both when there's
been an error and when there hasn't been one. So
why not go:
try {...}
catch(Exception) {}
doStuff();
instead of:
try {...}
catch(Exception) {}
finally {doStuff();}
?