This project has moved and is read-only. For the latest updates, please go here.

VB.NET error handling

Jan 9, 2014 at 2:12 AM
Hello Joe,
first, Thank you for this useful library! In order to strengthen my project, I'm looking for a VB example on how to handle errors issued by LinqToTwitter. I've seen some references to "TwitterQueryException", but I have no idea how to use it in VB. Any examples?

Jan 9, 2014 at 7:25 AM

TwitterQueryException is just like any other exception with a few special features for LINQ to Twitter:
  1. Strongly typed so you know it comes from a query to the Twitter API that couldn't complete.
  2. Two properties, ErrorCode and Message that come directly from the Twitter API.
  3. An InnerException with the WebException that .NET raised because of the HTTP Status Code.
You could use it like this:
        Dim credentials As IOAuthCredentials = New InMemoryCredentials

        credentials.ConsumerKey = "abc"
        credentials.ConsumerSecret = "123"

        Dim auth As PinAuthorizer = New PinAuthorizer()
        auth.Credentials = credentials
        twitterCtx = New TwitterContext(auth)

        Dim accounts = _
            From acct In twitterCtx.Account _
            Where acct.Type = AccountType.VerifyCredentials

            For Each Account In accounts
                Console.WriteLine("Credentials for account, {0}, are okay.", Account.User.Name)
        Catch ex As TwitterQueryException
            Console.WriteLine("Twitter did not recognize the credentials. Response from Twitter: " & ex.Message)
        End Try
Notice that I gave the authorizer bad credentials to force the exception.