I have this code:
using (var requestStream = request.GetRequestStream())
{
byte[] data = Encoding.UTF8.GetBytes(xmlData);
requestStream.Write(data, 0, data.Length);
}
If the request I'm making fails because the remote server is down, how do I catch the error?
Should I just expand out the using block to try-catch-finally, or is there a more elegant way this is done when using "using" blocks?
(I need to catch only server-being-down type errors this way - I need to show the client these errors happen because their server connection is inadequate, not because of bugs in our software or something).