473,387 Members | 3,820 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.

catching EOF errors

Hello,

I read a file from several classes and want to catch an EOF when it
appears.
Having caught the EOF I want to allow the final part of the program to
continue rather than just exiting.

At present I use methods which read from the file; test the read was
successful and return a 1 if not. This is then checked by the calling
method, which also returns a 1 if the other method returned 1 (thus
indicating the EOF) and so on...

As you can see, this is very clumsy and means that I have to
constantly check the return value. Sometimes this value is almost
passed back to main() several class levels away!

Also, where I use unsigned char methods, I do not know what character
to allocate to the EOF flag to return.

Does anyone know of a better design for this type of EOF catching?

Cheers
Fred
Jul 22 '05 #1
2 1721
fred wrote:
Hello,

I read a file from several classes and want to catch an EOF when it
appears.
Having caught the EOF I want to allow the final part of the program to
continue rather than just exiting.

At present I use methods which read from the file; test the read was
successful and return a 1 if not. This is then checked by the calling
method, which also returns a 1 if the other method returned 1 (thus
indicating the EOF) and so on...

As you can see, this is very clumsy and means that I have to
constantly check the return value. Sometimes this value is almost
passed back to main() several class levels away!

Also, where I use unsigned char methods, I do not know what character
to allocate to the EOF flag to return.
Why not just use int and... well, EOF?
Does anyone know of a better design for this type of EOF catching?


Throw an exception.
Jul 22 '05 #2
"fred" <jc****@space.qinetiq.com> wrote in message
news:19**************************@posting.google.c om...
Hello,

I read a file from several classes and want to catch an EOF when it
appears.
Having caught the EOF I want to allow the final part of the program to
continue rather than just exiting.

At present I use methods which read from the file; test the read was
successful and return a 1 if not. This is then checked by the calling
method, which also returns a 1 if the other method returned 1 (thus
indicating the EOF) and so on...
Why not pass a reference to the stream? (Either via return
or a parameter). Then you can query its 'state' bits (e.g. via 'eof()',
'fail()', etc.). That would enable you to distinguish between EOF and a
'real' error.

As you can see, this is very clumsy and means that I have to
constantly check the return value. Sometimes this value is almost
passed back to main() several class levels away!
You can achieve 'direct' communication across several 'levels'
with exceptions.

Also, where I use unsigned char methods, I do not know what character
to allocate to the EOF flag to return.


EOF is by definition a negative value, so storing it in an
unsigned type doesn't make much sense.

Use the "C++ way", and test your stream state.

-Mike
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Florian Fredegar Haftmann | last post by:
Hi! I'm working on a tool which helps in testing applications with web-frontends (on Windows) On thing I would like to test ist the occurence of JavaScript errors; the idea is that the test...
2
by: PapaBear | last post by:
Hi y'all, I'm handling Apache errors through seperate shtml files. That surely looks better than the standard error pages by the browser etc. I did this by coding in httpd.conf lines like: ...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
0
by: R. MacDonald | last post by:
Hi, I have a VB.Net application that dynamically calls unmanaged routines in a DLL that has been created by Fortran (DVF v5). The call to the DLL routine is within a Try/Catch block, but when...
2
by: Eric Lilja | last post by:
Hello, consider this complete program: #include <iostream> #include <string> using std::cout; using std::endl; using std::string; class Hanna {
1
by: Hari Sekhon | last post by:
I've written an except hook into a script as shown below which works well for the most part and catches exceptions. import sys def myexcepthook(type,value,tb): do something ...
4
by: John Pye | last post by:
Hi all I have some C code that is giving me some 'nan' values in some calculations. The C code is wrapped using SWIG to give me a Python module that I am then exercising through a unittest...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.