Groups | Blog | Home
all groups > dotnet general > august 2006 >

dotnet general : Exception Handling - .Net Runtime Error Unhandled Exceptions


Larry Herbinaux
8/31/2006 2:27:02 PM
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?
Larry Herbinaux
8/31/2006 4:01:01 PM
Note: I accidentally left out the top try:

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


[quoted text, click to view]
Brian Gideon
9/1/2006 8:19:13 AM
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

[quoted text, click to view]
Larry Herbinaux
9/3/2006 10:51:01 PM
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).

[quoted text, click to view]
AddThis Social Bookmark Button