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 () noexcept
 
virtual ~ErrorHandler ()
 
void verbosity (int v) noexcept
 Set desired verbosity level. More...
 
int verbosity () const noexcept
 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>
OIIO_FORMAT_DEPRECATED void info (const char *format, const Args &...args)
 
template<typename... Args>
OIIO_FORMAT_DEPRECATED void warning (const char *format, const Args &...args)
 
template<typename... Args>
OIIO_FORMAT_DEPRECATED void error (const char *format, const Args &...args)
 
template<typename... Args>
OIIO_FORMAT_DEPRECATED void severe (const char *format, const Args &...args)
 
template<typename... Args>
OIIO_FORMAT_DEPRECATED void message (const char *format, const Args &...args)
 
template<typename... Args>
OIIO_FORMAT_DEPRECATED void debug (const char *format OIIO_MAYBE_UNUSED, const Args &...args OIIO_MAYBE_UNUSED)
 
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 OIIO_MAYBE_UNUSED, const Args &...args OIIO_MAYBE_UNUSED)
 
template<typename... Args>
void infofmt (const char *format, const Args &...args)
 
template<typename... Args>
void warningfmt (const char *format, const Args &...args)
 
template<typename... Args>
void errorfmt (const char *format, const Args &...args)
 
template<typename... Args>
void severefmt (const char *format, const Args &...args)
 
template<typename... Args>
void messagefmt (const char *format, const Args &...args)
 
template<typename... Args>
void debugfmt (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 suppresses 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 30 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 36 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 48 of file errorhandler.h.

Constructor & Destructor Documentation

ErrorHandler::ErrorHandler ( )
inlinenoexcept

Definition at line 54 of file errorhandler.h.

virtual ErrorHandler::~ErrorHandler ( )
inlinevirtual

Definition at line 58 of file errorhandler.h.

Member Function Documentation

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

Definition at line 79 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED void ErrorHandler::debug ( const char *format  OIIO_MAYBE_UNUSED,
const Args &...args  OIIO_MAYBE_UNUSED 
)
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 134 of file errorhandler.h.

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

Definition at line 181 of file errorhandler.h.

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

Definition at line 228 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 75 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED 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 107 of file errorhandler.h.

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

Definition at line 162 of file errorhandler.h.

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

Definition at line 209 of file errorhandler.h.

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

Definition at line 73 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED 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 88 of file errorhandler.h.

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

Definition at line 148 of file errorhandler.h.

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

Definition at line 195 of file errorhandler.h.

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

Definition at line 77 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED 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 124 of file errorhandler.h.

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

Definition at line 174 of file errorhandler.h.

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

Definition at line 221 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 76 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED 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 115 of file errorhandler.h.

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

Definition at line 168 of file errorhandler.h.

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

Definition at line 215 of file errorhandler.h.

void ErrorHandler::verbosity ( int  v)
inlinenoexcept

Set desired verbosity level.

Definition at line 61 of file errorhandler.h.

int ErrorHandler::verbosity ( ) const
inlinenoexcept

Return the current verbosity level.

Definition at line 64 of file errorhandler.h.

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

Definition at line 74 of file errorhandler.h.

template<typename... Args>
OIIO_FORMAT_DEPRECATED 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 98 of file errorhandler.h.

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

Definition at line 155 of file errorhandler.h.

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

Definition at line 202 of file errorhandler.h.


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