Hi Adam,
A simple test reveals that the exception thrown by MethodC replaces the
previous exception thrown by MethodB, and its the MethodC exception that is
caught by the outer try...catch block:
static void Main(string[] args)
{
try
{
MethodA();
try
{
MethodB();
}
finally
{
MethodC();
}
}
catch (Exception ex)
{
Console.WriteLine("Catch: " + ex.Message);
}
}
static void MethodA()
{
Console.WriteLine("MethodA");
}
static void MethodB()
{
Console.WriteLine("MethodB");
throw new Exception("Exception from MethodB");
}
static void MethodC()
{
Console.WriteLine("MethodC");
throw new Exception("Exception from MethodC");
}
Result:
MethodA
MethodB
MethodC
Catch: Exception from MethodC
--
Dave Sexton
http://davesexton.com/blog http://www.codeplex.com/DocProject (Sandcastle in VS IDE)
"Adam Clauss" <ca*****@tamu.eduwrote in message
news:12*************@corp.supernews.com...
Consider the following code:
try
{
methodA();
try
{
methodB();
}
finally
{
methodC();
}
}
catch (Exception e)
{
//some sort of error handling
}
If methodA completes successfully, and methodB throws an exception,
methodC would then be called before the catch statement correct?
What happens if methodC then throws an exception? Which of those
exceptions get's handled in the catch? Is the other exception 'lost'?
--
Adam Clauss