When using asynchronous code to read from streams, etc. using the BeginXXX / EndXXX template, I believe that any exceptions that occur during the process will be thrown when EndXXX is called.
Does this mean that the initial BeginXXX call will never throw an exception, it will always be called EndXXX?
Or, in another way, should I include BeginRead with try {} catch {}?
public StartReading()
{
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);
}
catch(Exception ex)
{
}
}
source
share