"Consumed" with .ReadLine()

G

Guest

Hi All,

I was curious if an exception is generated with the .ReadLine() function (found in the StreamReader class), will the current line be consumed? Thus the next .ReadLine() will start at the next line.

I ask this, because if it an exception is generated i would like to retry the .ReadLine() from the same line without advancing to the next one. If the line is consumed, is there anyway to specify a line number to start reading at?

Thanks for all your help,

Kunk
 
J

Jay B. Harlow [MVP - Outlook]

Kunk,
I would take the approach that if ReadLine threw an exception then the
entire stream is bad!

In other words I do not see that the StreamReader could possible ensure you
could continue using it, once it threw any exception...

Just out of curiosity, what kind of exception do you see that ReadLine would
throw that would leave the StreamReader and underlying Stream in a
"guaranteed" usable state?

Hope this helps
Jay

Kunk said:
Hi All,

I was curious if an exception is generated with the .ReadLine() function
(found in the StreamReader class), will the current line be consumed? Thus
the next .ReadLine() will start at the next line.
I ask this, because if it an exception is generated i would like to retry
the .ReadLine() from the same line without advancing to the next one. If the
line is consumed, is there anyway to specify a line number to start reading
at?
 
G

Guest

Hi Jay,

First of all, thankyou for the response!

Secondly, I do not have very much experience accessing text files with the stream reader, so i was not sure what type of errors to expect (if any) from the readline() after succesfully executing
try
srStreamReader = File.OpenText(strFilePath)
catch ex as Exception
end try

normally i would not be so overly obessed with this type of problem when a person is running the program and can attempt to manually fix the error. But, i am writting a program that is run automatically from the network at night. it must access 3 different text files, pull data from each one and save it to a database. in short, there will be no human intervention and i would like to program to attempt to self recover before sending an autmated error e-mail to the man in charge.

so, i was wondering if ReadLine() threw an exception, will it consume the line or is there anyway to specify a line number to start reading at?

Thanks,

Kunk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top