473,796 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1751
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.q inetiq.com> wrote in message
news:19******** *************** ***@posting.goo gle.com...
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
2492
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 tool does many request and actions on the Internet Explorer and collects all errors (including JavaScript errors) together into a report. I've setted up a framework for controlling an Internet Explorer instance using Python and win32com, but so far I...
2
2511
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: ErrorDocument 403 http://levi.prodeo/errors/err_403.shtml ErrorDocument 404 http://levi.prodeo/errors/err_404.shtml ErrorDocument 405 http://levi.prodeo/errors/err_405.shtml
7
2341
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 of code, when System.Exception seems to get the job done for me. My application is an ASP.Net intranet site. When I catch an exception, I log the stack trace and deal with it, normally by displaying an error
0
1073
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 one of the DLL (Fortran) routines triggers a run-time error, the VB.Net application terminates rather than catching the error. Is there any way to be able to catch these Fortran run-time errors in
2
2368
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
2232
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 sys.excepthook=myexcepthook rest of script.... (now protected by catchall exception hook)
4
1966
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 suite. It seems that I should expect the C code to throw floating point exceptions (SIGFPE) and either the whole thing to abort, or for Python to catch the errors and report them. Instead I'm getting neither. I want to be able to track down the...
25
2373
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 of Global.asax ? Thanks, JJ
3
3289
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 the correct inputs for filetype #------------------------------- def readGrid( self, coord='xyz' ): mg = ( '.FALSE.', '.TRUE.' ) form = ( 'FORMATTED', 'UNFORMATTED' )
0
10452
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10221
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.