Normally, one writes code something like this to download some data using a WebRequest.
using(WebResponse resp = request.GetResponse()) // WebRequest reques
I have had a quick peek with Reflector, and can now say:
WebResponse
, being an abstract class, delegates all its closing/disposing behaviour to its derived classes.HttpWebResponse
, being the derived class you are almost certainly using here, in its close/dispose methods, is only concerned with disposing the actual response stream. The rest of the class state can be left to the GC's tender mercies.It follows that it's probably safe to do whatever you like with regard to exception handling, as long as:
WebResponse
in the try
block, enclose it in a using
block.WebException
in the catch
block, enclose it in a using
block as well.WebException
itself.