MGIS
Loading...
Searching...
No Matches
mgis::ErrorBacktrace Struct Reference

a structure to keep trace of error messages. More...

#include </home/runner/work/MFrontGenericInterfaceSupport/MFrontGenericInterfaceSupport/include/MGIS/ErrorBacktrace.hxx>

Inheritance diagram for mgis::ErrorBacktrace:
mgis::AbstractErrorHandler mgis::Context

Public Types

using ErrorReportFunction = std::string(*)(const int)
 brief a simple alias
 
using ErrorReport = std::variant< const char *, std::pair< int, ErrorReportFunction >, std::string >
 a simple alias listing the main way to report an error.
 

Public Member Functions

InvalidResult registerErrorMessage (const char *const) override final
 register a new error message
 
InvalidResult registerErrorMessage (const ErrorReport) noexcept
 register a new error message
 
InvalidResult registerErrorMessageWithoutSourceLocation (const ErrorReport) noexcept
 register a new error message
 
void clearErrorMessages () noexcept
 remove the error messages
 
std::string getErrorMessage (const bool=true) noexcept
 
std::string getRawErrorMessage (const bool=true) noexcept
 
bool empty () const noexcept
 
 ~ErrorBacktrace () noexcept override
 destructor
 
- Public Member Functions inherited from mgis::AbstractErrorHandler
virtual constexpr ~AbstractErrorHandler ()=default
 destructor
 

Static Public Member Functions

static void setErrorReportingAsFatal () noexcept
 specify if error reporting shall be fatal
 
static void unsetErrorReportingAsFatal () noexcept
 specify if error reporting shall be fatal
 

Detailed Description

a structure to keep trace of error messages.

The design of this class is inspired by the many solutions offered by the standard library (exceptions, std::error_code, etc...)

Member Typedef Documentation

◆ ErrorReport

using mgis::ErrorBacktrace::ErrorReport = std:: variant<const char *, std::pair<int, ErrorReportFunction>, std::string>

a simple alias listing the main way to report an error.

The alternatives way of reporting an error are:

  • a plain message in the form of a C-string
  • a message in the form of a std::string
  • an error code associated with a function allowing to retrieve an appropriate error message.

Building complex error message shall be avoided as much as possible in template code.

Member Function Documentation

◆ empty()

bool mgis::ErrorBacktrace::empty ( ) const
noexcept
Returns
if the list registered error messages is empty

◆ getErrorMessage()

std::string mgis::ErrorBacktrace::getErrorMessage ( const bool  = true)
noexcept
Returns
the registered error messages
Parameters
[in]bboolean. If true, the error message are cleared

◆ getRawErrorMessage()

std::string mgis::ErrorBacktrace::getRawErrorMessage ( const bool  = true)
noexcept
Returns
the error message without the decoration (file name, function name, line number)
Parameters
[in]bboolean. If true, the error message are cleared

◆ registerErrorMessage() [1/2]

InvalidResult mgis::ErrorBacktrace::registerErrorMessage ( const char * const  )
finaloverridevirtual

register a new error message

Parameters
[in]eerror message
Note
for convenience, this method always return an invalid object

Implements mgis::AbstractErrorHandler.

◆ registerErrorMessage() [2/2]

InvalidResult mgis::ErrorBacktrace::registerErrorMessage ( const ErrorReport  )
noexcept

register a new error message

Parameters
[in]eerror code
Note
for convenience, this method always return an invalid results

◆ registerErrorMessageWithoutSourceLocation()

InvalidResult mgis::ErrorBacktrace::registerErrorMessageWithoutSourceLocation ( const ErrorReport  )
noexcept

register a new error message

Parameters
[in]eerror code
Note
for convenience, this method always return InvalidResult

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