【发布时间】:2012-02-26 18:05:50
【问题描述】:
我有以下代码:
try
{
using (var myHttpWebResponse = (HttpWebResponse) httPrequestCreated.GetResponse())
{
var streamResponse = myHttpWebResponse.GetResponseStream();
if (streamResponse != null)
{
var streamRead = new StreamReader(streamResponse);
var readBuff = new Char[256];
var count = streamRead.Read(readBuff, 0, 256);
while (count > 0)
{
var outputData = new String(readBuff, 0, count);
finalResopnse += outputData;
count = streamRead.Read(readBuff, 0, 256);
}
streamRead.Close();
streamResponse.Close();
myHttpWebResponse.Close();
}
}
}
catch (WebException ex)
{
MessageBox.Show("something went wrong");
}
错误代码是404 Not Found,但我收到以下错误,而不是 MessageBox:
为什么从未捕获到异常?
【问题讨论】:
标签: c# .net exception exception-handling httpwebrequest