Thread: C++ Error Checking

  1. #1
    Registered User
    Join Date
    Jan 2009

    C++ Error Checking

    I want to implement a class and say for each of the method I add code for error checking (bounds,correct args etc..) However I do want the provide user with an option to disable error checking completely and when the user chooses this option the code for error checking shouldn't be executed. I could only think of conditional compilation adding a #ifdefs etc..
    What would be the best way to achieve this ?
    Just to clarify my case more:-
    I would want something similar to

    Any suggestions would be really appreciated.
    Thank you.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Do you want the checks to be removed at compile time or at run time?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2009
    If compile time i am guessing we would have to use conditional compilation.
    How about runtime ?

  4. #4
    Registered User
    Join Date
    Aug 2010
    Without much information I cannot guide you well, but all I can say is to drop error codes (if it is possible, that is, it is within your application) and use exceptions instead. You should always check return codes for functions and process them in the right way. Finally, output some error messages if the user requested them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help doing error checking
    By t_6 in forum C Programming
    Replies: 4
    Last Post: 05-29-2008, 08:23 PM
  2. Error Checking
    By jlharrison in forum C Programming
    Replies: 10
    Last Post: 02-12-2006, 05:31 PM
  3. Error Checking
    By Dangerous_Dave in forum C Programming
    Replies: 2
    Last Post: 11-12-2003, 02:30 PM
  4. NEED help with a Error checking
    By paulroseby in forum C Programming
    Replies: 7
    Last Post: 10-16-2002, 03:34 PM
  5. error checking
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 02-10-2002, 10:04 PM