21.1 Overview
The RoseErrorContext class is for libraries or applications that have defined their own codes. This class stores predefined errors as well as severity and logging information. The thresholds are normally handled by the RoseErrorReporter , but you can set local thresholds for each context. Report errors to the context and it will find or create the appropriate RoseError structure and pass it on to the error reporter.
The RoseError structure is used to create a static array of predefined errors. These are used with the RoseErrorContext class to define messages for a particular library or application. Note that error codes may be duplicated between contexts, but it is not advisable to do so.
21.2 RoseErrorContext Constructor
RoseErrorContext( RoseError * msgs, /* message array */ unsigned msgcnt /* message array size */ );
struct RoseError { RoseErrorCode f_errcode; RoseSeverity f_severity; char * f_message; };
The RoseErrorContext constructor creates an new error context and expects an array of pre-defined RoseError messages to be supplied.
Example
#define BAD_KEYWORD 100
#define NO_FILE 200
RoseError application_errors[] = {
{ BAD_KEYWORD, ROSE_SEV_WARNING, "Unknown keyword %s" },
{ NO_FILE, ROSE_SEV_WARNING, "Could not find %s" }
};
RoseErrorContext * application_ec() {
static RoseErrorContext * ec = 0;
/* Create the context on the first call. Do this rather than
* have a global with a static ctor so that we can report
* errors during static ctor calls if necessary.
*/
if (!ec) {
ec = new RoseErrorContext
(application_errors,
ROSE_COUNT (application_errors));
}
return ec;
}
See Also
21.3 <action>_threshold()
RoseSeverity exit_threshold();
RoseSeverity report_threshold();
void exit_threshold( RoseSeverity s );
void report_threshold( RoseSeverity s );
The error context keeps track of severity thresholds for reporting errors, and exiting the application. The error reporter only takes action if the severity of a message exceeds the threshold. Setting the thresholds to ROSE_SEV_FATAL turns off the action. The error reporter also has thresholds, but the thresholds in the error context will override these if they are set to something other than ROSE_SEV_NULL .
Example
The following example sets the reporting threshold so that informational messages are not printed.
RoseErrorContext * ec;
ec-> report_threshold (ROSE_SEV_WARNING);
See Also
RoseSeverity; RoseErrorReporter::<action>_threshold()
21.4 <error_severity>()
virtual void fatal( char * fmat, ... );
virtual void error( char * fmat, ... );
virtual void warning( char * fmat, ... );
virtual void message( char * fmat, ... );
These functions are used report general error conditions that do not have a pre-defined code for the report() function. The functions take variable arguments and use the printf() conventions, but no trailing newline is required.
Example
RoseErrorContext * ec;
RoseDesign * design;
ec-> message ("Design %s is happy", design-> name())
ec-> warning ("Design %s is not happy", design-> name())
ec-> error ("Design %s is extremely unhappy", design-> name())
ec-> fatal ("Design %s is so unhappy that we stop here", design-> name())
21.5 report() / va_report()
virtual void report( RoseErrorCode code, ... );
virtual void va_report( RoseErrorCode code, va_list ap );
The report() and va_report() functions are used to signal one of the pre-defined conditions. The RoseErrorCode corresponds to a predefined RoseError structure, which contains message text and a severity. The severity determines whether the message will be printed and/or logged, and whether the application will quit or continues as appropriate. The set of pre-defined conditions are specified when the error context is created.
The report() function takes variable arguments for printf() parameters within the pre-defined error message. The va_report() function is for reporting a condition from within a function that already takes variable arguments. The function uses the same convention as the vprintf() function.
Example
The following example uses the messages defined by the RoseErrorContext constructor example:
RoseErrorContext * ec;
ec-> report (BAD_KEYWORD, "OPEN");
ec-> report (NO_FILE, "/usr/local/widget");