Red Gate forums :: View topic - Exception not found, although thrown
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
Exception Hunter 1
Exception Hunter 1 forum

Exception not found, although thrown

Search in Exception Hunter 1 forum
Post new topic   Reply to topic
Jump to:  
Author Message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Mon May 26, 2008 10:12 pm    Post subject: Exception not found, although thrown Reply with quote

I have a particular piece of code where EH1 just reports one possible exception (System.ArgumentException) but it definitely throws a System.IndexOutOfRangeException

Here is the code in question:

Code:

      private const int _maxSegments = 10;
      private Object SyncRoot = new Object();
      private Bandwidth _bandwidth;
      private int[] _segments = new int[_maxSegments];
      private int _lastSegment;
      private long _maxBytesPerSegment;
      private long _currentlyUsedBytes;

      public void CountAndWait(int nBytes)
      {
         lock(SyncRoot)
         {
            int nTickCount = Environment.TickCount;

            int nTickSegment = (nTickCount / (1000 / _maxSegments)) % _maxSegments;
            _currentlyUsedBytes = SegmentSum();
            long maxBytes =   _bandwidth.MaxBytesPerSecond;

            if(maxBytes == 0 || _bandwidth.IsUnlimited)
            {
               return;
            }

            if(maxBytes < nBytes)
            {
               SegmentsClear();
               System.Threading.Thread.Sleep(1000);
               return;
            }

            if(_segments[nTickSegment] + nBytes > _maxBytesPerSegment)
            {
               System.Threading.Thread.Sleep(1000 / _maxSegments);

               nTickSegment = (nTickSegment + 1) % _maxSegments;
               _segments[nTickSegment] = nBytes;
            }
            else
            {
               _segments[nTickSegment] += nBytes;
            }

            int nOldestTickSegment = (nTickSegment + 1) % _maxSegments;
            if(_lastSegment != nTickSegment)
            {
               _segments[nOldestTickSegment] = 0;
               _lastSegment = nTickSegment;
            }
         }
      }


The two functions SegmentSum() and SegmentClear() do not throw any exception. _bandwidth is a settings container.

Any clues?
Back to top
View user's profile Send private message MSN Messenger
Brian Donahue



Joined: 23 Aug 2004
Posts: 6580

PostPosted: Thu May 29, 2008 9:15 am    Post subject: Reply with quote

Hi,

The best thing I can suggest is to turn on or off the use more detailed analysis setting. Exception Hunter tries to eliminate exceptions that cannot possibly happen based on conditional branches and the like. For instance if you test for a null and skip a line of code that can throw a null-reference exception based on the findings, Exception Hunter can work out that the null-reference can never logically happen.
Back to top
View user's profile Send private message
AndrewH



Joined: 17 Aug 2006
Posts: 137

PostPosted: Thu May 29, 2008 10:29 am    Post subject: Reply with quote

Hi,

I think you're encountering a limitation of the algorithm used by Exception Hunter: it does not report all possible exceptions generated by the .NET runtime. Usually when we can't determine with certainty whether or not an exception will be thrown we err on the side of caution and report it.

However, the IndexOutOfRangeException thrown by the runtime on some array accesses is an exception to this general rule. The problem is that our model doesn't extend to array sizes and has only limited support for integer values: not enough to ever be able to determine whether or not an array access is safe or not.

Array accesses are so common in the .NET framework that this means that we would report this exception for nearly every non-trivial function. The overwhelming majority of these would be from safe code that never throws the exception in reality. We decided that as this exception would be reported everywhere it would be better not to report it as it would be rare that the information is actually useful.

I think that there are improvements that may be made so that we could detect some more obvious cases where this could happen, though there would be concerns about the effect this would have on the performance of the tool.
_________________
Andrew Hunter
Software Developer
Red Gate Software Ltd.
Back to top
View user's profile Send private message
Uniwares_AS



Joined: 11 Oct 2007
Posts: 132

PostPosted: Thu May 29, 2008 3:07 pm    Post subject: Reply with quote

I understand. Yet its a curious case, since as far as I can see, there should be no possibility to exceed the bounds of the array, except if the tick count would be negative, which is not the case.

Already tried various settings to see if EH1 shows more info. Without success in this case.

Well, time to engage other tricks.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group