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

Use the error handling that already built in, called stdexcept

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.