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

A stackable ErrorHandler that prints context lines. More...

#include <error.hh>

Inheritance diagram for ContextErrorHandler:
ErrorVeneer ErrorHandler

Public Member Functions

 ContextErrorHandler (ErrorHandler *errh, const char *fmt,...)
 Construct a ContextErrorHandler.
 
bool context_printed () const
 Return true iff the context has already been printed.
 
void set_context_printed (bool x)
 Set whether the context has been printed.
 
void set_context (const String &str)
 Set the context string to str.
 
void set_indent (const String &str)
 Set the indent string to str.
 
void set_context_landmark (const String &str)
 Set the context landmark to str.
 
String decorate (const String &str)
 Decorate an error message.
 
- Public Member Functions inherited from ErrorVeneer
 ErrorVeneer (ErrorHandler *errh)
 Construct an ErrorVeneer.
 
String vformat (const char *fmt, va_list val)
 Format an error string.
 
String decorate (const String &str)
 Decorate an error message.
 
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 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

A stackable ErrorHandler that prints context lines.

The stackable ContextErrorHandler adds context to the first error message printed, and optionally indent error messages so that they appear grouped underneath the context.

FileErrorHandler errh1(stderr);
ContextErrorHandler errh2(&errh1, "While counting to 2:");
errh2.error("An error occurred.");
errh2.error("Another error occurred.");
// prints "While counting to 2:\n"
// " An error occurred.\n"
// " Another error occurred.\n"
A stackable ErrorHandler that prints context lines.
Definition error.hh:737
An ErrorHandler that prints error messages to a given file.
Definition error.hh:648

To prevent ContextErrorHandler from indenting or printing context for a message, add a "{context:no}" annotation to the message's first line. To turn off the indent but keep the context, add a "{context:noindent}" annotation.

FileErrorHandler errh1(stderr);
ContextErrorHandler errh2(&errh1, "While counting to 2:");
errh2.error("{context:no}An error occurred.");
errh2.error("Another error occurred.");
// prints "An error occurred.\n"
// "While counting to 2:\n"
// " Another error occurred.\n"
FileErrorHandler errh1(stderr);
PrefixErrorHandler noctx_errh(stderr, "{context:no}");
ContextErrorHandler errh2(&errh1, "While counting to 2:");
errh2.error("An error occurred.");
errh2.error("Another error occurred.");
// prints "An error occurred.\n"
// "Another error occurred.\n"
A stackable ErrorHandler that adds a prefix to error messages.
Definition error.hh:808

ContextErrorHandler adds the "{context:context}" annotation to context lines.

Constructor & Destructor Documentation

◆ ContextErrorHandler()

ContextErrorHandler::ContextErrorHandler ( ErrorHandler *  errh,
const char *  fmt,
  ... 
)

Construct a ContextErrorHandler.

Parameters
errhbase ErrorHandler
fmtformat for context lines

The context message is formed by errh->format() using fmt and any additional arguments.

Member Function Documentation

◆ context_printed()

bool ContextErrorHandler::context_printed ( ) const
inline

Return true iff the context has already been printed.

◆ set_context_printed()

void ContextErrorHandler::set_context_printed ( bool  x)
inline

Set whether the context has been printed.

◆ set_context()

void ContextErrorHandler::set_context ( const String &  str)
inline

Set the context string to str.

◆ set_indent()

void ContextErrorHandler::set_indent ( const String &  str)
inline

Set the indent string to str.

The indent string is prepended to all non-context messages. It can contain landmarks as well as non-landmark text. The default indent string is " " (two spaces).

◆ set_context_landmark()

void ContextErrorHandler::set_context_landmark ( const String &  str)
inline

Set the context landmark to str.

The context landmark is used to decorate the context, and also applied to any error messages that lack landmarks of their own. The default context landmark is empty.

Note
The input str is passed to ErrorHandler::make_landmark_anno().

◆ decorate()

String ContextErrorHandler::decorate ( const String &  str)
virtual

Decorate an error message.

Parameters
strerror message, possibly with annotations
Returns
decorated error message
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 decorate an error message before it is emitted. The input str is an error message string, possibly annotated. The default implementation returns str unchanged. Other ErrorHandlers might add context lines (ContextErrorHandler), prefixes (PrefixErrorHandler), or a default landmark (LandmarkErrorHandler).

Reimplemented from ErrorHandler.


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