Program class is catching exceptions that I've already caught

I am getting the error

InvalidArgument=Value of '4' is not valid for 'index'.

on

Application.Run(new Form1());

Intelletrace takes me up to this code:

        for (int i = 0; i < 20; i++)
        {
            try
            {
                if (dataBase.tagInclude.Count() == 0)
                {
                    commonTags.Add(dataBase.set.Tables["tagTable"].Select("tag like '*'", "count desc")[i]["tag"].ToString());
                }
                else
                {
                    commonTags.Add(dataBase.tagPruneList[i].tag);
                }
            }
            catch (IndexOutOfRangeException)
            {
                break;
            }
            catch (ArgumentOutOfRangeException)
            {
                break;
            }
        }

With the error being on catch (ArgumentOutOfRangeException)

I don't understand why it is doing this if I am not throwing the exception. Also it only just started doing this but this code has worked for some time and I haven't changed it recently. When I code it so that it doesn't throw an error it just does the same thing with a different line of code that has worked even longer.

The code I added seems pretty harmless and unrelated:

    public static void itemChecked(ListViewItem lvi)
    {
        if (supressChecks) return;
        if (!lvi.Checked)
        {
            dataBase.Tag(lvi.Tag.ToString());
        }
        else
        {

        }
    }

The only thing this code is doing differently is calling the dataBase.Tag() function with a listviewitem tag rather than a textbox.text.

Answers


You are catching:

IndexOutOfRangeException
ArgumentOutOfRangeException

But what is being thrown is:

 InvalidArgument

...according to the information in your post. It looks like a function is expecting a number and you are passing in a char or string. Catch the thrown exception.


Need Your Help

xcode objective c UIImageView animation lagging on startup

ios objective-c xcode animation uiimageview

Having a really strange issue. I have a UIImageView that moves randomly via NSTimer. The movement runs rather smoothly without any problems, but for some reason right when the view loads the animat...

Dynamic PHP combo box

php javascript html combobox

I have a registration form on my site where the date of birth is dynamic using JavaScript, where it changes the number in the days depending on the month (i.e. 28/29 in february, 31 in January etc....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.