前几天我收到了一个奇怪的错误报告,并希望有人能够帮助我找出罪魁祸首。我有一个插件,它使用Facebook API从桌面客户端程序拨打电话。用户报告说,当他打开Vista的家长控制时,他会遇到运行时异常。
The detailed bug report is available here,我已经确认Vista的家长控制确实是问题所在。即使没有网站被阻止,即使明确允许http://api.facebook.com
,我仍然会得到例外。
违规方法如下。具体来说,行string result = reader.ReadToEnd();
是抛出异常的地方。
private static XmlDocument ExecuteQuery(SortedDictionary<string, string> parameters,
string secretKey)
{
string query = GetQueryFromParameters(parameters, secretKey);
HttpWebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FACEBOOK_REST_URL);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
// Write the POST parameters to Facebook.
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(query);
writer.Close();
// Get a response.
response = request.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
// Getting the response must have thrown an HTTP error. We can still try to get the
// response from the caught exception though.
response = we.Response as HttpWebResponse;
}
if (response != null)
{
// Read the response.
StreamReader reader = new StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();
reader.Close();
response.Close();
XmlDocument responseXml = new XmlDocument();
responseXml.LoadXml(result);
return responseXml;
}
else
{
throw new FacebookException(Resources.FacebookResponseError);
}
}
显然,我应该捕获IOException,而不是让它成为运行时异常。但即便如此,问题仍然存在。我花了一些时间搜索这个问题,但没有提出任何与家长控制有关的事情。
有什么建议吗?谢谢!
答案 0 :(得分:1)
好吧,我无法弄清楚为什么抛出异常,但至少如果我抓住它并且什么也不做,那么读者仍然会读到最后并且所有结果都被保存