简体   繁体   中英

Unhandled Exception in c#

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 understand. any ideas on how to get rid of this error would be much appreciated

Unhandled Exception: System.ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
at System.String.Substring (Int32 startIndex, Int32 length) [0x00000]
at OpenWebSpiderCS.mysql.executeSQLQuery (System.String SQL) [0x00000]
at OpenWebSpiderCS.db.startIndexThisSite (OpenWebSpiderCS.page p) [0x00000]
at OpenWebSpiderCS.ows.startCrawling () [0x00000]
at OpenWebSpiderCS.mainClass.Main (System.String[] args) [0x00000] 

thank you

This exception tells that when you use Substring function you send startIndex and Length to it. And parameters you sent are invalid because startIndex+Length is more that the length of the whole string.

Just revise your code or check before

if (startIndex+Length < yourString.Length)

在Visual Studio中Ctrl+Alt+E并选择Break on Errors选项,您将看到错误位置。

so ive kind of worked out how this error has occured, basically in the mysql.cs file it is trying to executeSQLQuery where the sub string System.String.Substring (Int32 startIndex, Int32 length) has been set to SQL.Substring(0, 1000) , now there exists a variable in args.cs file which defines the variable length .

the read out on the console says startIndex + length > this.length Parameter name: length

im gussing that this is a generic message and that this.length points to the variable a.length in the args.cs file. any ideas on how to correct the error now?

i dont know if i should paste the files in here as they may be considered quite large. thanks for any help provided

the files can be downloaded from http://sourceforge.net/projects/openwebspider/files/OpenWebSpider%23/v0.1.4.1/OpenWebSpiderCS_v0.1.4.1.zip/download

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM