Thread safety?

Jul 7, 2014 at 7:52 PM
Hi,

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:
        _getExceptionInfos.Add(twitterException);
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,
C
Coordinator
Jul 7, 2014 at 11:29 PM
Hi,

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.
Linvi
Jul 8, 2014 at 1: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)
                {
                    webResponse.Dispose();
                }

                if (httpWebRequest != null)
                {
                    httpWebRequest.Abort();
                }

                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 3: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!
Coordinator
Jul 9, 2014 at 6: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?

Linvi

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