22.1 Overview
The RoseErrorReporter class handles the printing and disposal of all messages from the ROSE libraries. Only one error reporting object exists and is kept by the ROSE interface object. All error reporting goes through this object, and can be replaced with an instance of a subclass if alternate behavior is needed.
If you need to subclass the error reporter in order to customize your error control, you will need to redefine one or more of the following functions. These functions will be called if the exception exceeds the appropriate threshold.
virtual void do_report (char * prefix, RoseError *, va_list ap);
virtual void do_log (char * prefix, RoseError *, va_list ap);
virtual void do_quit (int exitcode);
The reporter class has a static member variable RoseErrorReporter::error_file that holds the destination for warnings and messages. By default, this is stdout , but can be changed as needed. An application that writes important data to stdout should change the error destination to stderr , so that messages will not be mixed with the normal program output.
The definition for the standard reporter function is shown below.
static FILE * RoseErrorReporter::error_file = stdout;
void RoseErrorReporter::do_report (
char * prefix,
RoseError * err,
va_list ap)
{
if (!error_file) error_file = stdout;
fputs (prefix, error_file);
vfprintf (error_file, error_file-> f_message, ap);
fputc ('\n', error_file);
}
22.2 <action>_threshold()
RoseSeverity report_threshold();
RoseSeverity exit_threshold();
void report_threshold( RoseSeverity s );
void exit_threshold( RoseSeverity s );
The error context keeps track of severity thresholds for reporting errors, and exiting the application. These are used if an error context does not specify thresholds of it's own. The error reporter only takes action if the severity of a message exceeds the threshold. Setting the thresholds to ROSE_SEV_FATAL will disable the action. The default value for the reporting and logging thresholds is ROSE_SEV_MESSAGE , and the default for exit ROSE_SEV_ERROR .
Example
The following example sets the reporting threshold so that informational messages are not printed.
ROSE.error_reporter()-> report_threshold (ROSE_SEV_WARNING);
See Also
RoseSeverity; RoseErrorContext::<action>_threshold(); RoseInterface::quiet()
22.3 errcode() / errcontext()
RoseErrorCode errcode();
RoseErrorContext * errcontext();
The errcode() function returns the numeric code for the last error seen, or zero if there was no error. The errcontext() function returns the context object that defines the error, or null if the error was a general one reported through error() or warning() . The reset() function can be used to clear the error status. The code ROSE_OK is defined as zero and reserved to signal no error.
See Also
RoseInterface::errcode() / errcontext()
22.4 log()
void log( RoseBoolean yn = ROSE_TRUE );
The log() function allows an application to explicitly start or stop logging of messages. Logging is normally turned on if the ROSE_LOG environment variable is set to a value. If the variable is set to a filename, the log will be written to that file, otherwise the log will be written to the file rose_log . The log file name can also be provided with the log_filename() function.
Example
The following code fragment turns on logging during an operation and then turns it back off again:
/* start logging */
ROSE.error_reporter()-> log_filename ("logfile");
ROSE.error_reporter()-> log();
[ ... some suspicious code ... ]
/* stop logging */
ROSE.error_reporter()-> log (ROSE_FALSE);
22.5 log_filename()
void log_filename( char * filename );
The log_filename() function allows an application to set the file that logging messages will be written to. This file is normally taken from the ROSE_LOG environment variable. If log_filename() is used, then the log() function must be used to turn on logging.
22.6 report() / va_report()
virtual void report( RoseErrorContext * context, RoseError * message_spec, ... );
virtual void va_report( RoseErrorContext * context, RoseError * message_spec, va_list ap );
The report() and va_report() functions are used to signal a message of some sort. The RoseError structure contains message text and a severity, and is usually taken from the error context. The context argument contains thresholds that will be used if they are set. The report() function takes variable arguments for printf() parameters within the 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.
22.7 reset()
void reset();
The reset() function clears the errcode() and errcontext() values.
See Also