Gyoto
|
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... | |
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 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:
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:
std::string Gyoto::Error::get_message | ( | ) | const |
Retrieve error message for custom handling of the exception.
See also operator const char * () const and getErrCode().
int Gyoto::Error::getErrcode | ( | ) | const |
Gyoto::Error::operator const char * | ( | ) | const |
Cast to const char *.
Retrieve error message as a C string. See also get_message() and gerErrcode().
|
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().
phandler | Function pointer to the handler. |
|
private |
Error code.
Default value is EXIT_FAILURE from cstdlib. Currently not used in practice.