Exception Handling - .Net Runtime Error Unhandled Exceptions

G

Guest

I have built an asychronous TCP Server that uses the thread pool. I have two
levels of exception handling in case the handling of the inner catch block
throws an exception. The outer catch block does nothing put print a string
literal to our logging mechanism. The general structure for this is:

AsyncReceiveCallback
{
try
{
OnReceiveDelegate();
}
catch (SocketException)
{
...
}
catch (ObjectDisposedException)
{
...
}
catch (Exception ex)
{
...
}
}
catch (Exception ex)
{
...
}
}

The OnReceiveDelegate is what handles the application business logic and
this business logic also has exception handling, but in some cases it may not
catch everything. My question here is shouldn't my exception handling in the
AsyncReceiveCallback method catch any unhandled exception returning from the
OnReceiveDelegate method?
 
G

Guest

Note: I accidentally left out the top try:

AsyncReceiveCallback
{
try
{
try
{
OnReceiveDelegate();
}
catch (SocketException)
{
...
}
catch (ObjectDisposedException)
{
...
}
catch (Exception ex)
{
...
}
}
catch (Exception ex)
{
...
}
}
 
B

Brian Gideon

Larry,

Yes. It should catch any exception thrown by OnReceiveDelegate. In
fact, it should catch any exceptions thrown by the catch blocks of the
inner try-catch block as well. The only way AsyncReceiveCallback can
throw an exception is if the outer catch block generates it. Are you
observing different behavior?

Brian
 
G

Guest

Brian,

Yes we are having some exceptions that cause a .Net Runtime error. We have
at least one general business logic exception that we are looking into, but
we also see it in our production environment when we switch from one DB
Cluster Node to another (not all the time...but this could be to timing
issues...e.g. in the middle of a SQL Request or not when switch occurs).
 

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