Weird exception behavior


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
 
Ad

Advertisements

O

olive_fr

[...]
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.

You can't reproduce it in that short example, because it's not plausible
that it happens.

What is happening is that in your _real_ code, it is complicated enough
that it's misleading you as to where and how the exceptions are being
thrown and caught, and so you're misinterpreting your observations.

If and when you can post a concise-but-complete code example that
reliably demonstrates the behavior you're asking about, then it will be
possible to say specifically what it is about your observation that has
gone awry.  In the meantime, all that can be said is that two different
catch clauses in the same try/catch block are not going to be invoked by
the same exception.

Pete


Hi,

There is no misinterpretation of the behavior. The DLL we are using is
enhanced by code injection from Telerik OpenAccess and we finally
found out that they completely screw the MSIL code! More strange
behavior (leading to InvalidProgramException) have been found because
of their enhancer and reported to their support.

My advide to those using OpenAccess would be the following: STOP USING
IT, it's full of bugs and everytime they correct something they
introduce regressions!

O. Rouit
 
Ad

Advertisements

A

Arne Vajhøj

[...]
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.

You can't reproduce it in that short example, because it's not plausible
that it happens.

What is happening is that in your _real_ code, it is complicated enough
that it's misleading you as to where and how the exceptions are being
thrown and caught, and so you're misinterpreting your observations.

If and when you can post a concise-but-complete code example that
reliably demonstrates the behavior you're asking about, then it will be
possible to say specifically what it is about your observation that has
gone awry. In the meantime, all that can be said is that two different
catch clauses in the same try/catch block are not going to be invoked by
the same exception.
There is no misinterpretation of the behavior. The DLL we are using is
enhanced by code injection from Telerik OpenAccess and we finally
found out that they completely screw the MSIL code!

The the code shown was not the code executing.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top