Solved

debugging versions

Posted on 1998-05-08
5
227 Views
Last Modified: 2010-04-10
I have a program in which the previous programmer has used a flag (called AL_DEBUG) to specify whether a program is a debug or release version.  When AL_DEBUG is set conditional compile statements include extra run time error handling code.  Note this is not done by exception handling.  Most of the code is for simply checking pointers to make sure they contain an object before continuing.  I assume that this is easily done by exception handling but would it lead to unnecessary code bloat?  I am quite happy with the fact that my AL_DEBUG flag is in no way compiler dependent and so my code is relatively portable at the moment. Also - does anyone know of a good book that covers exception handling in detail as I don't have one at the moment.
0
Comment
Question by:gavinpat
  • 4
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1174823
First I would recomend "C++ Programming Language" by Bjarne Stroustrup  It covers exceptions and everything else.   (It is not devoted to exceptions, but I don't know of any that are).  

continued.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174824
Exceptions are a very powerful way to deal with errors, but they are best used for handling errors that are "predictable"  but that I mean that there are some errors that you expect to have happen from time to time and have a way to recover from them.  Things like trying to open a file that was there a minute ago and now is not.  Or trying to allocate memory and finding there is not enough free memory.  In contrast often there are errors that you sort of never expect to have occur--after the code is debugged.  Like writing 100 bytes to a file and finding that the file length is 99 bytes.

Exceptions are good for the first kind of error.  This is because the error can occur in a final release version and because you can handle the error (somewhat) gracefully).  However, the second type of errors are best handled by asertions (ASSERT()) or conditional code that is removed in the final product.  They could be handled, by exceptions, but there is usually no point as, (1) they will almost never occur in the final product, (2) there is no way to handle them gracefully, (3) the overhead of exceptions is realitvely minimal, but is not worth it because if 1 and 2.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1174825
As to the code bloat (and run-time inneficiency) of exceptions, I recomend you look at "More Effective C++" by scott meyers.  It has a section on this in particular.  
0
 

Author Comment

by:gavinpat
ID: 1174826
I will have to have a look at the section you mention in More Effective C++. I am wondering how much you use the set_new_handler referred to in item 7 in Effective C++ as I am playing around with that and would like to use it. At the moment the code I am debugging has some strange characteristics e.g. loops that change the value of the loop counter! Thanks once again for the help.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1174827
I use set new handler.  My library creates a 32K block at startup as a safety net.  Then if new fails, I release part of this 32K block and display a message notifying the user that memory is low and they should try to close down unneeded components of the system.  Then I allow the new to retry, hopefully it will succeed because memory was freed from the initially grabbed 32K.

Are your loop counters being changed  by legitimately,  For example, in

for (int i = 5; i <= 10 ++i)
{
   i = 0
}

the loop counter will legitimately be changed to 0 and the loop will continue for ever.  Or do you have a weird bug that is causing the loop counter to be altered when it should not be?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TTimer no longer functioning 7 84
object oriented programming on screen browser tutorial lesson 2 75
Arduino EDI - Programming language 3 79
Issues with C++ Class 19 78
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now