TryReceive and Exceptions
After an earlier article about receiving messages, Kenny Wolf suggested that I talk about the exception model for TryReceive. As you'll recall, Receive works by waiting for a message and then throwing an exception if no message arrives. TryReceive uses a softer failure model, where the failure to receive a message does not result in an exception. If no message arrives during the call to TryReceive, then that is indicated with a boolean return value from the method. This failure model doesn't mean that TryReceive will never throw an exception. If a message arrives but it is malformed and cannot be processed, then a boolean return value is not rich enough to describe that (remember, the return value only tells us whether or not a message arrived). In that case, TryReceive will throw an exception just like any other variation of the Receive method. You can apply the same reasoning to BeginTryReceive and EndTryReceive to figure out how those methods must work compared to BeginReceive and EndReceive.
Next time: The Try-Catch-Abort Pattern
Comments
Anonymous
May 01, 2007
In the last article on call context initializers , the sample program included three bindings to tryAnonymous
October 31, 2007
We're back to the channel pump for another round. In the previous channel pump article we had introduced