A first chance exception of type 'System.Net.WebException' occurred in System.dll

23,409

Solution 1

I assume when you say "First chance exception" you mean the message that is output to the Debug console? That message is output whenever an exception is thrown. The exception may be caught by code and handled and not allowed to propagate up the stack. TweetSharp may be catching this exception within its code and handling in some way so it never reaches your catch block

This is normal and only the debugger displays this message. If this is a problem for you in some way (other than the message displaying in the Output window), please provide more detail.

Solution 2

I was looking something else, really, but this cought my eye. If you are planning to rethrow exception then you want to replace this

catch (WebException e) { throw e; }

with this so you won't mess up the stacktrace.

catch (WebException e) { throw; }
Share:
23,409
Only Bolivian Here
Author by

Only Bolivian Here

Updated on July 09, 2022

Comments

  • Only Bolivian Here
    Only Bolivian Here almost 2 years

    I'm using TweetSharp to find the followers for a user.

    Here is the code:

    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;
        }
    }
    

    I've tried wrapping the code in a try/catch, to catch the WebException error being fired and review it's InnerException, but the catch is never entered despite the error message being shown in the output window (View -> Output) in Visual Studio.

    How can I see the inner exception of this breaking bug? This is the first time I've seen the debugger not firing the catch when an exception is fired.

  • samiretas
    samiretas about 9 years
    Actually, if you're not doing anything in the catch block (like logging it) and just rethrowing it, don't even include the exception handling, as that's what would happen anyway.
  • Mikko Viitala
    Mikko Viitala about 9 years
    True that, missed the obvious information :) Still, never "throw e".