O
olive_fr
HI,
I'm experiencing a very strange behavior of a try/catch block.
Unfortunately I can't reproduce it with a simple test program, but
here is what's happening:
class Program
{
static void Main(string[] args)
{
try
{
GlobalMethod();
}
catch
{
Console.WriteLine("Global catch");
}
}
static void Method()
{
throw new TestException();
}
static void GlobalMethod()
{
try
{
Method();
}
catch (TestException)
{
Console.WriteLine("TestException handling");
throw;
}
catch (Exception ex)
{
Console.WriteLine("Exception handling " +
ex.ToString());
throw ex;
}
}
}
class TestException : Exception
{
}
In the full application when the TestException is caught by the
catch(TestException) and thrown again, it is caught again by the
catch(Exception) at the same level. This doesn't happen in this test
program but the pattern is similar.
If anyone already experienced this behavior and knows why it happens,
please give me the reason so I maybe able to understand what's
happening in my own code.
Thks
Olivier
I'm experiencing a very strange behavior of a try/catch block.
Unfortunately I can't reproduce it with a simple test program, but
here is what's happening:
class Program
{
static void Main(string[] args)
{
try
{
GlobalMethod();
}
catch
{
Console.WriteLine("Global catch");
}
}
static void Method()
{
throw new TestException();
}
static void GlobalMethod()
{
try
{
Method();
}
catch (TestException)
{
Console.WriteLine("TestException handling");
throw;
}
catch (Exception ex)
{
Console.WriteLine("Exception handling " +
ex.ToString());
throw ex;
}
}
}
class TestException : Exception
{
}
In the full application when the TestException is caught by the
catch(TestException) and thrown again, it is caught again by the
catch(Exception) at the same level. This doesn't happen in this test
program but the pattern is similar.
If anyone already experienced this behavior and knows why it happens,
please give me the reason so I maybe able to understand what's
happening in my own code.
Thks
Olivier