HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ErrorHandler Class Reference

#include <errorhandler.h>

+ Inheritance diagram for ErrorHandler:

Public Types

enum  ErrCode {
  EH_NO_ERROR = 0, EH_MESSAGE = 0 << 16, EH_INFO = 1 << 16, EH_WARNING = 2 << 16,
  EH_ERROR = 3 << 16, EH_SEVERE = 4 << 16, EH_DEBUG = 5 << 16
}
 
enum  VerbosityLevel { QUIET = 0, NORMAL = 1, VERBOSE = 2 }
 

Public Member Functions

 ErrorHandler ()
 
virtual ~ErrorHandler ()
 
void verbosity (int v)
 Set desired verbosity level. More...
 
int verbosity () const
 Return the current verbosity level. More...
 
virtual void operator() (int errcode, const std::string &msg)
 
void info (const std::string &msg)
 
void warning (const std::string &msg)
 
void error (const std::string &msg)
 
void severe (const std::string &msg)
 
void message (const std::string &msg)
 
void debug (const std::string &msg)
 
template<typename... Args>
void info (const char *format, const Args &...args)
 
template<typename... Args>
void warning (const char *format, const Args &...args)
 
template<typename... Args>
void error (const char *format, const Args &...args)
 
template<typename... Args>
void severe (const char *format, const Args &...args)
 
template<typename... Args>
void message (const char *format, const Args &...args)
 
template<typename... Args>
void debug (const char *format, const Args &...args)
 
template<typename... Args>
void infof (const char *format, const Args &...args)
 
template<typename... Args>
void warningf (const char *format, const Args &...args)
 
template<typename... Args>
void errorf (const char *format, const Args &...args)
 
template<typename... Args>
void severef (const char *format, const Args &...args)
 
template<typename... Args>
void messagef (const char *format, const Args &...args)
 
template<typename... Args>
void debugf (const char *format, const Args &...args)
 

Static Public Member Functions

static ErrorHandlerdefault_handler ()
 

Detailed Description

ErrorHandler is a simple class that accepts error messages (classified as errors, severe errors, warnings, info, messages, or debug output) and handles them somehow. By default it just prints the messages to stdout and/or stderr (and supresses some based on a "verbosity" level).

The basic idea is that your library code has no idea whether some application that will use it someday will want errors or other output to be sent to the console, go to a log file, be intercepted by the calling application, or something else. So you punt, by having your library take a pointer to an ErrorHandler, passed in from the calling app (and possibly subclassed to have arbitrarily different behavior from the default console output) and make all error-like output via the ErrorHandler*.

Definition at line 56 of file errorhandler.h.

Member Enumeration Documentation

Error categories. We use broad categories in the high order bits. A library may just use these categories, or may create individual error codes as long as they have the right high bits to designate their category (file not found = ERROR + 1, etc.).

Enumerator
EH_NO_ERROR 
EH_MESSAGE 
EH_INFO 
EH_WARNING 
EH_ERROR 
EH_SEVERE 
EH_DEBUG 

Definition at line 62 of file errorhandler.h.

VerbosityLevel controls how much detail the calling app wants.

Enumerator
QUIET 

Show MESSAGE, SEVERE, ERROR only.

NORMAL 

Show MESSAGE, SEVERE, ERROR, WARNING.

VERBOSE 

Like NORMAL, but also show INFO.

Definition at line 74 of file errorhandler.h.

Constructor & Destructor Documentation

ErrorHandler::ErrorHandler ( )
inline

Definition at line 80 of file errorhandler.h.

virtual ErrorHandler::~ErrorHandler ( )
inlinevirtual

Definition at line 84 of file errorhandler.h.

Member Function Documentation

void ErrorHandler::debug ( const std::string msg)
inline

Definition at line 105 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::debug ( const char *  format,
const Args &...  args 
)
inline

Debugging message with printf-like formatted error message. This will not produce any output if not in DEBUG mode, or if verbosity is QUIET.

Definition at line 162 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::debugf ( const char *  format,
const Args &...  args 
)
inline

Definition at line 208 of file errorhandler.h.

static ErrorHandler& ErrorHandler::default_handler ( )
static

One built-in handler that can always be counted on to be present and just echoes the error messages to the console (stdout or stderr, depending on the error category).

void ErrorHandler::error ( const std::string msg)
inline

Definition at line 101 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::error ( const char *  format,
const Args &...  args 
)
inline

Error message with printf-like formatted error message. Will print regardless of verbosity.

Definition at line 135 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::errorf ( const char *  format,
const Args &...  args 
)
inline

Definition at line 189 of file errorhandler.h.

void ErrorHandler::info ( const std::string msg)
inline

Definition at line 99 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::info ( const char *  format,
const Args &...  args 
)
inline

Use with caution! Some day this will change to be fmt-like rather than printf-like.

Definition at line 116 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::infof ( const char *  format,
const Args &...  args 
)
inline

Definition at line 175 of file errorhandler.h.

void ErrorHandler::message ( const std::string msg)
inline

Definition at line 103 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::message ( const char *  format,
const Args &...  args 
)
inline

Prefix-less message with printf-like formatted error message. Will not print if verbosity is QUIET. Also note that unlike the other routines, message() will NOT append a newline.

Definition at line 152 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::messagef ( const char *  format,
const Args &...  args 
)
inline

Definition at line 201 of file errorhandler.h.

virtual void ErrorHandler::operator() ( int  errcode,
const std::string msg 
)
virtual

The main (or "full detail") method – takes a code (with high bits being an ErrCode) and writes the message, with a prefix indicating the error category (no prefix for "MESSAGE") and error string.

void ErrorHandler::severe ( const std::string msg)
inline

Definition at line 102 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::severe ( const char *  format,
const Args &...  args 
)
inline

Severe error message with printf-like formatted error message. Will print regardless of verbosity.

Definition at line 143 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::severef ( const char *  format,
const Args &...  args 
)
inline

Definition at line 195 of file errorhandler.h.

void ErrorHandler::verbosity ( int  v)
inline

Set desired verbosity level.

Definition at line 87 of file errorhandler.h.

int ErrorHandler::verbosity ( ) const
inline

Return the current verbosity level.

Definition at line 90 of file errorhandler.h.

void ErrorHandler::warning ( const std::string msg)
inline

Definition at line 100 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::warning ( const char *  format,
const Args &...  args 
)
inline

Warning message with printf-like formatted error message. Will not print unless verbosity >= NORMAL (i.e. will suppress for QUIET).

Definition at line 126 of file errorhandler.h.

template<typename... Args>
void ErrorHandler::warningf ( const char *  format,
const Args &...  args 
)
inline

Definition at line 182 of file errorhandler.h.


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