API Flag Setting, is there no better way?

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 64
Reputation: chunalt787 is an unknown quantity at this point 
Solved Threads: 1
chunalt787 chunalt787 is offline Offline
Junior Poster in Training

API Flag Setting, is there no better way?

 
0
  #1
Sep 18th, 2009
I am writing a database API in C++ and I cant seem to think of a good way to handle the errors. For example if certain error conditions are met I would like to set some sort of error flag and allow every class to check that flag. I have the following classes

Database
Table (included in Database)
Column (included in Table)

I want to set some sort of flag in Column if an error is found and then check it on the next function call to a function of table or database. I was thinking I would create an error class as follows:
  1. class Error
  2. {
  3. bool error;
  4. string message;
  5.  
  6. Error() {
  7. error = false;
  8. message = " ";
  9. }
  10.  
  11. bool isError() { return error;
  12. string getMessage() { return message; }
  13. }
An Error object would be initialized in the Database class(top level class) but to set it I would have to have return types that could somehow pass up to Database every time. Is there a way to make a flag that every class can see and access? That or is there a better way to do this that I am missing? I really don't like to waste the overhead of passing info up and down the chain.

Thanks!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,459
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 189
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: API Flag Setting, is there no better way?

 
0
  #2
Sep 18th, 2009
Use the error handling that already built in, called stdexcept
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle.
2) Problem 2[b]solved by : jonsca
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 8
Reputation: David Boon is an unknown quantity at this point 
Solved Threads: 2
David Boon's Avatar
David Boon David Boon is offline Offline
Newbie Poster

Re: API Flag Setting, is there no better way?

 
0
  #3
Sep 19th, 2009
Thanks for information, actually I was looking for this, if you want know more information about c++ static analysis keep visit this forum.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 211 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC