By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,625 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,625 IT Pros & Developers. It's quick & easy.

Unhandled Exception. System.ArgumentOutOfRangeException

P: 2
i am currently trying to run a web crawler through the terminal. it compiles fine and the debug does not find any errors, however i get the following error which i do not under stand.
any ideas on how to get rid of this error would be much appreciated

Expand|Select|Wrap|Line Numbers
  1. Unhandled Exception: System.ArgumentOutOfRangeException: startIndex + length > this.length
  2. Parameter name: length
  3.   at System.String.Substring (Int32 startIndex, Int32 length) [0x00000]
  4.   at OpenWebSpiderCS.mysql.executeSQLQuery (System.String SQL) [0x00000]
  5.   at OpenWebSpiderCS.db.startIndexThisSite ( p) [0x00000]
  6.   at OpenWebSpiderCS.ows.startCrawling () [0x00000]
  7.   at OpenWebSpiderCS.mainClass.Main (System.String[] args) [0x00000]
Apr 11 '10 #1
Share this Question
Share on Google+
4 Replies

Expert 2.5K+
P: 3,525
Read error messages like this backwards.
The first line is the most recent...
it was caused by the line below it...
which came from the line below it.
The error message is a history.

If we read it from the bottom, upward... You should see the very process your program follows, right up to line that fails.

mainClass started
String.Substring (startIndex, length)

Then your error...
Unhandled Exception: System.ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length

So you have a function that is working the substring of some variable starting at "startIndex" for "this.Length" number of characters.

The error is telling you that parameter "length" isn't valid - and that you have not correctly handled that exception.

So if you fed in a string 20 characters long... and your startIndex is 10 and you try to go for a length of 20 FROM THAT START INDEX you would end at character 30. Well you can't end at character 30 out of 20, can you?

Now that you have an explanation, read the error again. Does it make more sense?

System.ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length

startIndex + length is greater than this.length
That number is out of the range of characters available to work with.
Apr 11 '10 #2

P: 2
thank you for your explanation, the code is from an open source project so i don't know the code intimately. however from your explanation i'm guessing that this.length in the "args" file needs to be made larger. the substring on line 4 of the read out is SQL.substring(0, 1000). does this mean i have to change this.length to be equal or greater to 1000?

all your help is much appreciated.

thank you
Apr 12 '10 #3

Expert 2.5K+
P: 3,525
I know nothing about the open source project you got the code from.

Personally I try to avoid just guessing and thrashing about and making changes all whilly nilly in the hopes I get lucky. You might make a change that solves it in your test environment but next will can still fail in the real world.

I think you should make an effort to actually understand the code and make meaningful *improvements*, not just changes.

Since this is an open source project, there should be many people working on it. It might be best to ask others that contributed to explain the code to you so you better understand it.
Apr 12 '10 #4

Expert 100+
P: 2,057
The length is too big, not too small.

Basically you've got a string, say "String".
If you ask for -> you get
substring(0,3) -> "Str"
substring(3,3) -> "ing"
substring(1,4) -> "trin"
substring(3, 5) -> ERROR.

Are you sure you're using the right type of substring function?
This code appears to use the type of substring function like this:
substring(startIndex, length)
whereas other substring functions may be written like this:
substring(startIndex, endIndex).

To convert it properly, you want:
substring(startIndex, endIndex - startIndex)
assuming this is your error.
Apr 13 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.