本文介绍了抛出WebException但从未被捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
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我收到以下错误:
The error code is 404 Not Found
, but instead of a MessageBox I get the following error:
为什么没有捕获到异常?
Why is the exception never caught?
推荐答案
您可能在Visual Studio中有第一次机会异常捕获。
You probably have first chance exception catching turned on in Visual Studio.
尝试运行不带调试器的应用程序(Ctrl + F5)。或者,如果您收到此对话框,您可以按运行(F5)获取您的消息框。
Try running the application without debugger (Ctrl+F5). Or, if you get this dialog, you can press Run (F5) to get your message box.
这篇关于抛出WebException但从未被捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!