Gyoto
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
Gyoto::Error Class Reference

Class for thowing exceptions. More...

#include <GyotoError.h>

Public Types

typedef void Handler_t(const Error)
 Error handler type. More...
 

Public Member Functions

 Error (const std::string m)
 Constructor with an error message.
 
 Error (const Gyoto::Error &o)
 
void Report () const
 Print-out error message on standard error.
 
int getErrcode () const
 Retrieve error code. More...
 
 operator const char * () const
 Cast to const char *. More...
 
std::string get_message () const
 Retrieve error message for custom handling of the exception. More...
 

Static Public Member Functions

static void setHandler (Gyoto::Error::Handler_t *phandler)
 Set application error handler. More...
 

Private Attributes

const std::string message
 Error message.
 
const int errcode
 Error code. More...
 

Detailed Description

Class for thowing exceptions.

Gyoto dlopens its plug-ins. The throw/catch C++ mechanism cannot pass the dlopen boundary. The Gyoto::Error mechanism alleviates this C++ language limitation.

Every Gyoto method (either in the main Gyoto library or in a Gyoto plug-in) should check for possible error conditions and throw adequate Gyoto::Error exceptions through the GYOTO_ERROR macro (which calls the Gyoto::throwError() function). For instance:

if (error_condition) GYOTO_ERROR("Useful error message");

If the main code has set Gyoto::Error::handler_t error handler using Gyoto::Error::setHandler(), these errors will then be passed to it. Else, the Error is C++-thrown at the main Gyoto library level, above the dlopen boundary.

The main code can then catch these exceptions and act appropriately, for instance:

try { gyoto_code ; }
catch (Gyoto::Error err)
{
err.Report();
abort();
}

Member Typedef Documentation

◆ Handler_t

typedef void Gyoto::Error::Handler_t(const Error)

Error handler type.

Instead of catching Gyoto errors directly (for instance if gyoto itself is dlopened), you can set a Handler_t error handler using setHandler().

A very simple handler could be:

void applicationErrorHandler(const Gyoto::Error e) {
e.Report();
exit ( e.getErrCode() );
}

Member Function Documentation

◆ get_message()

std::string Gyoto::Error::get_message ( ) const

Retrieve error message for custom handling of the exception.

See also operator const char * () const and getErrCode().

Returns
char* message : pointer to the error message

◆ getErrcode()

int Gyoto::Error::getErrcode ( ) const

Retrieve error code.

See also operator const char * () const and get_message().

Returns
Error code

◆ operator const char *()

Gyoto::Error::operator const char * ( ) const

Cast to const char *.

Retrieve error message as a C string. See also get_message() and gerErrcode().

◆ setHandler()

static void Gyoto::Error::setHandler ( Gyoto::Error::Handler_t phandler)
static

Set application error handler.

Instead of catching Gyoto errors directly (for instance if gyoto itself is dlopened), you can set an Error::Handler_t error handler using setHandler().

void applicationErrorHandler(const Gyoto::Error e) {
e.Report();
exit ( e.getErrCode() );
}
int main() {
Gyoto::Error::setHandler(&applicationErrorHandler);
}
Parameters
phandlerFunction pointer to the handler.

Member Data Documentation

◆ errcode

const int Gyoto::Error::errcode
private

Error code.

Default value is EXIT_FAILURE from cstdlib. Currently not used in practice.


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