System.dll中发生了类型为“System.Net.WebException”的第一次机会异常
本文关键字:System 第一次 异常 机会 WebException dll 发生了 类型 Net | 更新日期: 2023-09-27 18:35:04
我正在使用TweetSharp来查找用户的关注者。
这是代码:
public static void FindFollowersForUser(TwitterUserModel twitterUser)
{
try
{
var followers = service.ListFollowersOf(twitterUser.TwitterName, -1);
if (followers == null) return;
while (followers.NextCursor != null)
{
var foundFollowers = service.ListFollowersOf(twitterUser.TwitterName, (long)followers.NextCursor);
if (foundFollowers == null) continue;
Debug.WriteLine("Followers found for: " + twitterUser.TwitterName);
foreach (var follower in foundFollowers)
{
twitterUser.Followers.Add(follower.ScreenName);
}
}
}
catch (WebException e)
{
throw e;
}
}
我尝试将代码包装在try/catch中,以捕获正在触发的WebException错误并查看其InnerException,但是尽管错误消息显示在Visual Studio的输出窗口(View -> Output
)中,但从未输入过捕获。
如何查看此重大错误的内部异常?这是我第一次看到调试器在触发异常时不触发 catch。
我假设当您说"第一次机会异常"时,您指的是输出到调试控制台的消息? 每当引发异常时,都会输出该消息。 异常可能会被代码捕获并处理,并且不允许向上传播堆栈。 TweetSharp可能会在其代码中捕获此异常并以某种方式进行处理,因此它永远不会到达您的catch
块
这是正常现象,只有调试器显示此消息。 如果这在某种程度上是您的问题(除了"输出"窗口中显示的消息),请提供更多详细信息。
我真的在看别的东西,但这让我眼前一亮。如果您打算重新抛出异常,那么您需要替换它
catch (WebException e) { throw e; }
有了这个,你就不会搞砸堆栈跟踪。
catch (WebException e) { throw; }