Figure 4-1. class Error
namespace Oracle
{
struct Error: public exception
{
// constructors
Error(
const string&,
const string&,
const string& = "",
const int = 0);
Error(const Error&);
// accessors
string str() const;
// data members
string module;
string msg;
string fname;
int line;
ostringstream desc;
};
ostream& operator<<(ostream&, const Error&);
}Error(const string& module_name, const string& error_message, const string& file_name, const int line_number);
Error(const Error& initial_value);
When you throw an Error object, you specify the module_name and the error_message, and optionally the file_name and line_number. You may specify the file name and line number using the pre-defined macros __FILE__ and __LINE__.
If you wish to provide addtional information, such as the names and values of local variables, you may write to the desc data member as you would any output stream.
This function returns a formatted string containing the values of all data members that have been set. It may look like any of the following:
In module_name: error_message
In module_name (file file_name): error_message
In module_name (file file_name, line line_number): error_message description
The description is the value of desc and, if provided, follows the error message on a new line. Any of the three examples above may or may not display the description.
This is the module or function name and is required by the constructor.
This is the error message and is required by the constructor.
This is the name of the source file where the error was thrown. A value of empty (""), the default, will be considered by the str() function to be unspecified.
This is the line number where the error was thrown. A value of zero, the default, will be considered by the str() function to be unspecified.
This ostringstream can be filled with additional descriptive information, such as the names and values of local variables.
This function provides the ability to write the results of the str() directly to an output stream.