Gyoto::Error Class Reference

Class for thowing exceptions. More...

#include <GyotoError.h>

List of all members.

Public Types

typedef void Handler_t (const Error)
 Error handler type.

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.
 operator const char * () const
 Cast to const char *.
std::string get_message () const
 Retrieve error message for custom handling of the exception.

Static Public Member Functions

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

Private Attributes

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

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::throwError() function. For instance:

  if (error_condition) Gyoto::throwError("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

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

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
int Gyoto::Error::getErrcode (  )  const

Retrieve error code.

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

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

Cast to const char *.

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

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:
phandler Function pointer to the handler.

Member Data Documentation

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:

Generated on 6 May 2017 for Gyoto by  doxygen 1.6.1