473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

"Consumed" with .ReadLine()

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
2 1473
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Geoffrey | last post by:
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer:...
19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
2
by: Paul Klanderud | last post by:
I'm encountering a strange situation with a .config file for a simple windows form test harness I built to test some components normally invoked by a windows service. My config file,...
0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
30
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that...
4
by: Kevin Goodsell | last post by:
The return value of sscanf should be "the number of input items assigned" (unless an input failure occurs before any conversion). Are items assigned due to a "%n" directive included in the returned...
30
by: kj | last post by:
My book (Flanagan's JavaScript: The Definitive Guide, 5th ed.) implies on page 111 that the following two constructs are equivalent: ( x.constructor == Foo ) and ( x instanceof Foo ) The...
8
by: clyfish | last post by:
In cmd, I can use find like this. C:\>netstat -an | find "445" TCP 0.0.0.0:445 0.0.0.0:0 LISTENING UDP 0.0.0.0:445 *:* C:\> And os.system is OK....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.