Search code examples
c#.netlinqtwittertweetinvi

Why is my code not throwing me an error?


I am currently exploring my first third party lib and everything is working fine except for that it should be throwing me an error when something is wrong which it doesn't..

So this is my code, and I've tried causing an error and it should be causing an error but its not, the app still runs

When I remove a letter or number from the consumer key for example, it doesnt connect and it should throw me an error.

I was looking over the docs and I was trying to follow this

Destroying a Friendship

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Tweetinvi;
using Tweetinvi.Core.Authentication;
using Tweetinvi.Core;
using Tweetinvi.Credentials;
using Tweetinvi.WebLogic;

namespace Tweetinvi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string accessToken;
        string accessTokenSecret;
        string consumerKey;
        string consumerSecret;
        string hashTag;
        string userName;



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)

        {
            try
            {
                Auth.SetUserCredentials(consumerKeyBox.Text, consumerSecretBox.Text, accessTokenBox.Text, accessTokenSecretBox.Text);
                Tweet.PublishTweet("Hello World :)");
                //User.UnFollowUser("");
            }
            catch(Exception ex)
            {
                MessageBox.Show("Something went wrong");
            }



        }
    }
}

Solution

  • It's not throwing an exception because there isn't one to throw.

    When you publish a tweet from twitter it should return an object that you can inspect. If the publishTweet() method fails, it might not throw an exception, instead it will return a response object.

    inspect that object and handle accordingly.