Results 1 to 11 of 11

Thread: Error I simply don't understand

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Question Error I simply don't understand

    I am having a program bug that makes absolutely no sense to me.

    First issue: The program runs fine most of the time (it is a desktop gadget-type program that updates itself every few hours). However, this is the second time (over the past months) that it threw an error.

    Second issue: When I shut the program down and restart it, I get the same error. However, when I open it in Visual Studio and run it, no error.

    Here is the error:
    Index was outside the bounds of the array.
    at xxx.vb: Line1
    at xxx.vb: Line2
    at xxx.vb: Line3

    But this makes no sense at all:
    Line1: Dim currentMonth As Integer = DateTime.Now.Month (this line of code is in SubOne)
    Line 2: Dim myDocFor As New XDocument (this line of code is in SubTwo, but SubOne is called three lines after this)
    Line 3: SubTwo()

    What the heck is going on???

    Note: Typing this up took about ten minutes and the program is again running properly. In case it matters, it is about 5:00 pm local time.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Error I simply don't understand

    Show us the actual code and the actual stack trace for the exception. No pictures though please. Copy the information from VS or the app and paste it as text, formatted appropriately. The exception make sense but you need to look at the actual information provided to see what it is. The stack trace will tell you exactly where the exception was thrown and the path of execution to get there. The first order of business is to determine what array the error message is referring to. You then need to determine what the upper bound of that array is and what index is actually being used. Once you've done that, it will be obvious that the index is greater than the upper bound of the array. You then have to determine where that index came from and why it's incorrect. Note that the line that actually throws the exception may not be in your code. It may be in a first- or third-party method you're calling. The data causing the exception is likely coming from your code though.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Re: Error I simply don't understand

    Thanks. As indicated, this issue happens infrequently and I need to figure out how to get a stack trace. But, you have provided me with some ideas of how to learn more.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Error I simply don't understand

    You could probably open the Windows Event Viewer, expand Windows Logs, and select Application. From there you can do a search for your application name and get the exception message from the details.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Re: Error I simply don't understand

    Thanks for the suggestion: I did as you indicated, but found nothing from my app (and I checked all five log categories at around the time of the issue).

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Error I simply don't understand

    That's kind of odd. I would have expected unhandled exceptions to wind up in the event viewer, but that's not always the case.

    The only thing I could recommend at this point is to copy/paste the relevant code like JMcIlhinney suggested.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Error I simply don't understand

    What it means is that at the time you tried to access an array or collection, that an index you’re trying to access doesn’t exist.
    We need to see your code.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Re: Error I simply don't understand

    What's truly baffling me is this: The error just occurred again. So, I shutdown the program, reran it, and the error occurred again. So, I opened the program in VS, ran it from within VS, and no error. This makes tracking things down really tough.

    Also, the error only seems to happened at about this time of day.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    158

    Re: Error I simply don't understand

    I may have just found the bug - silly mistake because I forgot that arrays are zero based.

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Error I simply don't understand

    Quote Originally Posted by groston View Post
    I may have just found the bug - silly mistake because I forgot that arrays are zero based.
    That'd do it

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Error I simply don't understand

    Just be sure to mark the thread as resolved. You can do this by selecting: Thread Tools > Mark Thread Resolved
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width