Thread safety?

Jul 7, 2014 at 8:52 PM

From what I gather in the code (unless I miss something), Tweetinvi.Logic.Exceptions.ExceptionHandler is a singleton - owned by the static Tweetinvi.ExceptionHandler.

In the AddWebException, there is this line:
Isn't this unsafe as far as concurrency is concerned, then?

As a collateral note, _getExceptionInfos keeps growing - which is not desireable for the case where this is used in a server application.

Thank you very much,
Jul 8, 2014 at 12:29 AM

You are totally right. The purpose of the ExceptionHandler is to help developers of simple applications to manage the huge amount of Exceptions that can be thrown by Twitter.

You can get rid of it by just setting the value like this:
ExceptionHandler.SwallowWebExceptions = false;
In this case you will have to manage all the exceptions on your own. You can use the class TwitterException to help you.
It will simply get the data from a webexception and transform it such as you can easily understand what went wrong.

Hope this helps.
Jul 8, 2014 at 2:16 AM
Thank you! That would sound right, but even when I set ExceptionHandler.SwallowWebExceptions = false; it still ends up in that code (in the:
    public TwitterException AddWebException(WebException webException, string url)
being raised from:
        catch (AggregateException aex)
            var webException = aex.InnerException as WebException;
            if (webException != null)
                if (webResponse != null)

                if (httpWebRequest != null)

                if (httpWebRequest != null)
                    ___var twitterException = _exceptionHandler.AddWebException(webException, httpWebRequest.RequestUri.AbsoluteUri);___
                    throw twitterException;

                throw webException;
My code basically does a search with 1000 => which will call SearchTweetsRecursively...
Jul 9, 2014 at 4:55 PM
Am I mistaken in my observation above (with respect to the singleton ExceptionHandler being used even if I set SwallowWebException to false (and that is wrong as it'll use a List<T> in a non thread safe way)? If my observation is correct, is there a suggestion you might have for me?

Thank you!
Jul 9, 2014 at 7:16 PM
Hi there,

Well I agree with you, I might have to add a new option in order to authorize the ExceptionHandler to log any exception.
Also concerning the Thread safety, I will try to work on that and ensure that the collection is accessed within a lock.

Does it sound find with you?


PS : Sorry for the delays of my responses.
Jul 9, 2014 at 7:30 PM
Awesome, thank you very much!