954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

API Flag Setting, is there no better way?

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:

class Error
{
	bool error;
	string message;

	Error() {
		error = false;
		message = " ";
	}

	bool isError() { return error;
	string getMessage() { return message; }
}

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!!

chunalt787
Junior Poster in Training
84 posts since Apr 2008
Reputation Points: 39
Solved Threads: 1
 

Use the error handling that already built in, called stdexcept

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

Thanks for information, actually I was looking for this, if you want know more information about c++ static analysis keep visit this forum.

David Boon
Newbie Poster
8 posts since Apr 2009
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You