Best way to report errors in class objects

This is a discussion on Best way to report errors in class objects within the C++ Programming forums, part of the General Programming Boards category; I've been learning C++ the past couple of months, and I've found myself writing C in C++, as I come ...

  1. #1
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478

    Best way to report errors in class objects

    I've been learning C++ the past couple of months, and I've found myself writing C in C++, as I come from years of writing C.

    I am writing a class that uses a lot of windows API stuff, and it's divided into several functions, some of them private for internal use and some public for the user.
    I have a dilemma, however. I'm not sure what would be the best way to report errors from inside my class. As you can imagine, there are a lot of different errors that can be reported, for a lot of the functions that get called inside my class's functions.
    For some reason, I find that simply returning error values would be bad design, and I'd have to have a ........load of custom error values because in a lot of cases, several different APIs can return the same general error, which isn't good for debugging.

    What would be the best way to report errors? Should I be using exceptions? I have never really used them in C++(I know how to use them from C# though).

    I would really appreciate some advice from the resident C++ gurus.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  2. #2
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    I'm not a guru but I'd go with exceptions/error codes for library/production. For debug builds, LINE/FUNCTION macro and printf or assert or whichever. I'd never return errors.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by Dae View Post
    I'm not a guru but I'd go with exceptions/error codes for library/production. For debug builds, LINE/FUNCTION macro and printf or assert or whichever. I'd never return errors.
    Thanks - I'll go with exceptions.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  2. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 10:33 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Global variables used in a linked class, getting errors.
    By RealityFusion in forum C++ Programming
    Replies: 3
    Last Post: 09-24-2005, 12:25 AM
  5. Class Errors (LNK2005)
    By NMZ in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2005, 02:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21