Click
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FileErrorHandler Class Reference

An ErrorHandler that prints error messages to a given file. More...

#include <error.hh>

Inheritance diagram for FileErrorHandler:
ErrorHandler

Public Member Functions

 FileErrorHandler (FILE *f, const String &prefix=String())
 Construct a FileErrorHandler.
 
void set_default_flags (int default_flags)
 
String vformat (const char *fmt, va_list val)
 Format an error string.
 
void * emit (const String &str, void *user_data, bool more)
 Output an error message line.
 
void account (int level)
 Account for an error message at level level.
 
- Public Member Functions inherited from ErrorHandler
 ErrorHandler ()
 Construct an ErrorHandler.
 
void debug (const char *fmt,...)
 Print a debug message (level el_debug).
 
void message (const char *fmt,...)
 Print an informational message (level el_info).
 
int warning (const char *fmt,...)
 Print a warning message (level el_warning).
 
int error (const char *fmt,...)
 Print an error message (level el_error).
 
int fatal (const char *fmt,...)
 Print a fatal error message (level el_fatal).
 
void ldebug (const String &landmark, const char *fmt,...)
 Print a debug message with a landmark annotation.
 
void lmessage (const String &landmark, const char *fmt,...)
 Print an informational message with a landmark annotation.
 
int lwarning (const String &landmark, const char *fmt,...)
 Print a warning message with a landmark annotation.
 
int lerror (const String &landmark, const char *fmt,...)
 Print an error message with a landmark annotation.
 
int lfatal (const String &landmark, const char *fmt,...)
 Print a fatal error message with a landmark annotation.
 
int xmessage (const String &str)
 Print an annotated error message.
 
int xmessage (const String &anno, const String &str)
 Print an error message, adding annotations.
 
int xmessage (const String &anno, const char *fmt, va_list val)
 Format and print an error message, adding annotations.
 
int xmessage (const String &landmark, const String &anno, const String &str)
 Print an error message, adding landmark and other annotations.
 
int xmessage (const String &landmark, const String &anno, const char *fmt, va_list val)
 Format and print an error message, adding landmark and other annotations.
 
int nerrors () const
 Return the number of errors reported via this handler.
 
String format (const char *fmt,...)
 Format an error string.
 
virtual String decorate (const String &str)
 Decorate an error message.
 
virtual void clear ()
 Clear accumulated error state.
 

Additional Inherited Members

- Public Types inherited from ErrorHandler
enum  Level {
  el_abort = -999 , el_fatal = -1 , el_emergency = 0 , el_alert = 1 ,
  el_critical = 2 , el_error = 3 , el_warning = 4 , el_notice = 5 ,
  el_info = 6 , el_debug = 7
}
 Error level constants. More...
 
enum  ConversionFlags {
  cf_zero_pad = 1 , cf_plus_positive = 2 , cf_space_positive = 4 , cf_left_just = 8 ,
  cf_alternate_form = 16 , cf_singlequote = 32 , cf_uppercase = 64 , cf_signed = 128 ,
  cf_negative = 256 , cf_utf8 = 1024
}
 
typedef String(* ConversionFunction) (int flags, VA_LIST_REF_T)
 
- Static Public Member Functions inherited from ErrorHandler
static ErrorHandler * static_initialize (ErrorHandler *errh)
 Initialize the ErrorHandler implementation.
 
static void static_cleanup ()
 Tear down the ErrorHandler implementation.
 
static ErrorHandler * default_handler ()
 Return the default ErrorHandler.
 
static void set_default_handler (ErrorHandler *errh)
 Set the default ErrorHandler to errh.
 
static ErrorHandler * silent_handler ()
 Return the global silent ErrorHandler.
 
static String xformat (int default_flags, const char *fmt,...)
 Format an error string.
 
static String vxformat (int default_flags, const char *fmt, va_list val)
 
static String xformat (const char *fmt,...)
 
static String vxformat (const char *fmt, va_list val)
 
static String make_anno (const char *name, const String &value)
 Create an error annotation.
 
static String combine_anno (const String &str, const String &anno)
 Apply annotations from anno to every line in str.
 
static const char * parse_anno (const String &str, const char *begin, const char *end,...) ERRH_SENTINEL
 Parse error annotations from a string.
 
static const char * skip_anno (const char *begin, const char *end)
 Skip a string's error annotations.
 
static String make_landmark_anno (const String &x)
 Return a landmark annotation equal to x.
 
static String clean_landmark (const String &landmark, bool colon=false)
 Clean the landmark.
 
static Conversion * add_conversion (const String &name, ConversionFunction func)
 
static int remove_conversion (Conversion *conversion)
 
- Static Public Attributes inherited from ErrorHandler
static const char e_abort [] = "<-999>"
 Error level indicators.
 
static const char e_fatal [] = "<-1>"
 
static const char e_emergency [] = "<0>"
 
static const char e_alert [] = "<1>"
 
static const char e_critical [] = "<2>"
 
static const char e_error [] = "<3>"
 
static const char e_warning [] = "<4>"
 
static const char e_warning_annotated [] = "<4>warning: "
 
static const char e_notice [] = "<5>"
 
static const char e_info [] = "<6>"
 
static const char e_debug [] = "<7>"
 
static const int ok_result = 0
 
static const int error_result = -EINVAL
 

Detailed Description

An ErrorHandler that prints error messages to a given file.

FileErrorHandler is the typical base ErrorHandler used at user level. It prints messages to a file passed in to the constructor, and calls exit() or abort() based on the error level.

Constructor & Destructor Documentation

◆ FileErrorHandler()

FileErrorHandler::FileErrorHandler ( FILE *  f,
const String &  prefix = String() 
)

Construct a FileErrorHandler.

Parameters
ffile to print errors
prefixstring to prefix every error line

Member Function Documentation

◆ vformat()

String FileErrorHandler::vformat ( const char *  fmt,
va_list  val 
)
virtual

Format an error string.

Parameters
fmtformat string
valargument list
Warning
ErrorHandler users don't need to call this function directly; it is called implicitly by the error()/xmessage() functions.

This virtual function is called to format an error message. The default implementation returns the result of vxformat(fmt, val).

Reimplemented from ErrorHandler.

◆ emit()

void * FileErrorHandler::emit ( const String &  str,
void *  user_data,
bool  more 
)
virtual

Output an error message line.

Parameters
strerror message line, possibly with annotations
user_datacallback data, 0 for first line in a message
moretrue iff this is the last line in the current message
Returns
user_data to be passed to emit() for the next line
Warning
ErrorHandler users don't need to call this function directly; it is called implicitly by the error()/xmessage() functions.

After calling decorate(), ErrorHandler splits the message into individual lines and calls emit() once per line. ErrorHandler subclasses should output the error lines as appropriate; for example, FileErrorHandler outputs the error message to a file.

str does not contain a newline, but may contain annotations, including a landmark annotation. Most ErrorHandlers use parse_anno() to extract the landmark annotation, clean it with clean_landmark(), and print it ahead of the error message proper.

ErrorHandler can handle multi-line error messages. However, the emit() function takes a line at a time; this is more useful in practice for most error message printers. The user_data and more arguments can help an ErrorHandler combine the lines of a multi-line error message. user_data is null for the first line; for second and subsequent lines, ErrorHandler passes the result of the last line's emit() call. more is true iff this is the last line in the current message.

The default emit() implementation does nothing.

Reimplemented from ErrorHandler.

◆ account()

void FileErrorHandler::account ( int  level)
virtual

Account for an error message at level level.

Parameters
levelminimum error level in the message
Warning
ErrorHandler users don't need to call this function directly; it is called implicitly by the error()/xmessage() functions.

After calling emit() for the lines of an error message, ErrorHandler calls account(), passing the minimum (worst) error level of any message line (or 1000 if no line had a level). The default implementation updates the nerrors() counter. Some other ErrorHandlers add account() behavior that, for example, exits after printing messages at el_fatal level or below.

Reimplemented from ErrorHandler.


The documentation for this class was generated from the following files: