|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Socket.BeginReceive errorCode parameterHello!
In .NET 2.0 Socket.BeginReceive has a new overloaded version: public IAsyncResult BeginReceive ( byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, Object state ) My question is about errorCode parameter. What it is for? Is it for returning error code in case of a socket error? But why then this version of BeginReceive throws SocketException as MSDN says? Thanks in advance. The SocketException class has a member called ErrorCode that is an integer.
This code can be any of about 50 different numbers, each signifying a different kind of error, returned from the underlying socket. The SocketError parameter is an enum. By calling the ToString() method on it, you can get a meaningful string that is more human-readable for diagnostic purposes. -- Show quoteHTH, Kevin Spencer Microsoft MVP Printing Components, Email Components, FTP Client Classes, Enhanced Data Controls, much more. DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net "Alexander Smirnov" <s_alexande***@list.ru> wrote in message news:1176190400.542378.258180@w1g2000hsg.googlegroups.com... > Hello! > > In .NET 2.0 Socket.BeginReceive has a new overloaded version: > > public IAsyncResult BeginReceive ( > byte[] buffer, > int offset, > int size, > SocketFlags socketFlags, > out SocketError errorCode, > AsyncCallback callback, > Object state ) > > My question is about errorCode parameter. What it is for? Is it for > returning error code in case of a socket error? But why then this > version of BeginReceive throws SocketException as MSDN says? > > Thanks in advance. > So the purpose of errorCode parameter is only for conveniance? I hoped
that it is alternative way to get info about function success or failure without try{} catch{}. I'm not sure I would say "only." ;-)
There is quite a lot in the .Net Framework that is for the "convenience" (i.e. "productivity") of the developer, including language enhancements such as anonymous methods, etc. I have spent quite awhile looking up socket error codes myself, and I can testify that having an enumeration is quite helpful! But as for "an alternative way to get info about function success or failure without try {} cat{}" I would have to say no. The SocketError enumeration does include a few "success" codes, but if the socket doesn't throw an exception, you're not likely to need them. All computer functions return numeric values, and for many years Microsoft used them. But the .Net programming model uses Exceptions which don't have numeric values (numbers are highly counter-intuitive as descriptions to humans), but messages instead. I believe that the enumeration is for the benefit (productivity) of the developer/debugger. -- Show quoteHTH, Kevin Spencer Microsoft MVP Printing Components, Email Components, FTP Client Classes, Enhanced Data Controls, much more. DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net "Alexander Smirnov" <s_alexande***@list.ru> wrote in message news:1176209014.923804.212630@d57g2000hsg.googlegroups.com... > So the purpose of errorCode parameter is only for conveniance? I hoped > that it is alternative way to get info about function success or > failure without try{} catch{}. > > |
|||||||||||||||||||||||