Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Easier discrimination of exceptions?
cambler

From: Redmond, WA USA
Posts: 102
Member Since: 04/14/03
posted April 27, 2003 11:17 PM

Is there an easier way to discriminate between exceptions other than parsing the "message" field?

What leads me to ask is that it would be much easier if I could, in the EndReceive() handler, do something like

if (e.Exception != null)
{
 if (e.Exception.Type == SomeNameSpace.Timeout)
 {
 // handle timeout condition here
 }
 else
 {
 // handle all other exceptions here
 }
}

See what I'm getting at? Doing a string compare is bad for 2 reasons - first, it's slow. Second, the message might change in future versions, whereas an enumerated type is reasonably steady, especially if intended for such use.

Just a thought...

Christopher
K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted April 29, 2003 11:37 AM

Hi Christopher,
First, exceptions can be differentiated based on their class. For example, you may have code that looks like:

try {...}
catch (System.Net.Sockets.SocketException sEx) {...}
catch (Dart.PowerTCP.Sockets.ProtocolException pEx) {...}
catch (Exception ex) {...} 

Furthermore, for SocketExceptions (such as Timeout), you can examine the NativeErrorCode property for an identifier that would not change (for example, 10060 for a timeout error).

Hope it helps,
-ken

K M Drake



From: Utica, NY USA
Posts: 3406
Member Since: 07/14/00
posted April 29, 2003 11:41 AM

Hi,
As an addendum to the above, to check the type in the EndX events:

if (e.Exception is System.Net.Sockets.SocketException) {...}

-ken
cambler

From: Redmond, WA USA
Posts: 102
Member Since: 04/14/03
posted April 29, 2003 12:50 PM

Native error - thanks, that's what I was getting at. I didn't realize that you percolate that up.

Thanks!
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX