When using asynchronous code to read from streams etc using the BeginXXX / EndXXX pattern, I believe that any exceptions that occur during the process will be thrown when the call to EndXXX is made.
Does this mean that the initial call to BeginXXX will never throw an exception, it will always be thrown by EndXXX?
Or to put it another way, should I enclose BeginRead with try{}catch{} as well?
public StartReading()
{
// Should this be enclosed with try{}catch{} ?
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(readCallback), stream);
}
private void readCallback(IAsyncResult result)
{
Stream stream = (Stream)result.AsyncState;
try
{
int len = stream.EndRead(result);
// Do work...
}
catch(Exception ex)
{
// Error handling stuff.
}
}