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

"Consumed" with .ReadLine()

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <da*******@hotmail.com> wrote in message
news:F9**********************************@microsof t.com...
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

Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.