Reference: Error

From DaevsGUI

Jump to: navigation, search

This file defines a few debugging and error handling functionalities. For output to std::cerr for log entries or warning messages, one would use LOG or WARNING (or their GLOBAL variants). The former is mostly useful for brute-force debugging, the latter for non-fatal errors (for example, you might call a function that has no effect in the current conditions but still has a performance impact or something else unnecessary, these are situations where a WARNING might be used). LOG and GLOBAL_LOG are not used in distributed version of the library. ASSERT is used to validate input information to functions. In these cases we assert that the library-user passed valid values (such as non-NULL pointers), or that certain function calls are valid in the current conditions.

ERROR and GLOBAL_ERROR are used for exceptional cases. Such as when a constructor fails, or when something is really wrong. This will throw an exception of type DaevsCommon::Exception. This class holds information such as the message about the origin of the error, as well as line number, file name, function name, etc.

If you suspect that the library crashes at some point, be sure to run the debug version. All feedback is very much appreciated, at the forums for instance.

Contents

Definitions

__FUNCTION__
set to '?' whenever _MSC_VER <= 1200
GLOBAL_LOG(message)
when NDEBUG is set this does nothing, otherwise will stream a log entry to std::cerr
will not output any information such as line number, file name or function name
LOG(message)
when NDEBUG is set this does nothing, otherwise will stream a log entry to std::cerr
outputs information such as line number, file name and function name
GLOBAL_WARNING(message)
when NDEBUG is set this does nothing, otherwise will stream a warning entry to std::cerr
will not output any information such as line number, file name or function name
WARNING(message)
when NDEBUG is set this does nothing, otherwise will stream a warning entry to std::cerr
outputs information such as line number, file name and function name
GLOBAL_ERROR(message)
will stream the message to a std::stringstream object and pass this to DaevsCommon::Exception
DaevsCommon::Exception will be thrown as an exception
will not output any information such as line number, file name or function name
ERROR(message)
will stream the message to a std::stringstream object and pass this to DaevsCommon::Exception
DaevsCommon::Exception will be thrown as an exception
outputs information such as line number, file name and function name
ASSERT(expression)
when NDEBUG is set this does nothing, otherwise will call assert(expression)

Enumerations

DaevsCommon::ExceptionType::Enum

  • Warning
  • Error

DaevsCommon::ExceptionLocality::Enum

  • Local
  • Global

Classes

DaevsCommon::Exception

class Exception
{
public:
    Exception(const char *i_message = "", ExceptionType::Enum i_type = ExceptionType::Error, ExceptionLocality::Enum i_locality = ExceptionLocality::Global, const char *i_file = NULL, const char *i_function = NULL, unsigned int i_line = 0);
 
    ////////////////
 
    const char *what() const;    // full error message including (when of type ExceptionLocality::Local) line number, file name and function name
    const char *message() const; // error message as passed by ERROR(message) or GLOBAL_ERROR(message), describing the problem
 
    ExceptionType::Enum type() const; // DaevsCommon::ExceptionType::Error
    const char *type_text() const;    // "error"
 
    ExceptionLocality::Enum locality() const; // either DaevsCommon::ExceptionLocality::Local or DaevsCommon::ExceptionLocality::Global, whether ERROR(message) or GLOBAL_ERROR(message) was invoked respectively
 
    const char *file() const;     // file name in which ERROR(message) or GLOBAL_ERROR(message) was invoked
    const char *function() const; // function name in which ERROR(message) or GLOBAL_ERROR(message) was invoked
    unsigned int line() const;    // line number where ERROR(message) or GLOBAL_ERROR(message) was invoked
};

Example

int value = 500;
 
GLOBAL_LOG("log information: " << value);
LOG("log information: " << value);
 
GLOBAL_WARNING("warning information: " << value);
WARNING("warning information: " << value);
 
try
{
    // very simplified
    GLOBAL_ERROR("error information: " << value);
    ERROR("error information: " << value);
}
catch (DaevsCommon::Exception &exception)
{
    std::cerr << " -- " << exception.what() << std::flush;
    throw;
}
 
ASSERT(value > 256);
Views
Personal tools
Other