Question

I'm using the Azure SDK to upload a stream to an Azure Storage Blob. I want to do it async, so I use CloudPageBlob.BeginUploadFromStream. Doing this, I started to think about what would happen if an exception is thrown while reading the stream. I couldn't find any information on if the exception would bubble up, so I could catch it with a try catch, or if the method would call the async callback, or what would happen.

To try it out, I wrapped my stream in a class that inherits Stream, and the constructor takes my stream as an argument, and keep it as a private variable. Each inherited method then just call its equal on the private stream. In the Read() however, I throw an exception, to see what would happen if something goes wrong while reading the stream. I then pass an instance of my streamwrapper to BeginUploadFromStream(), instead of the actual stream.

It turns out, when an exception is thrown, BeginUploadFromStream() completes and call the async callback, and no exception bubble up to where the method was first called, so I cannot catch it with a try catch. At the same time, I cannot find any info on the IAsyncResult passed to the callback, that an exception was thrown.

What can I do to be able to act on the fact that BeginUploadFromStream() didn't complete as expected?

Was it helpful?

Solution

I believe you'll see the exception when you call EndUploadFromStream.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top