Typical use is like this:
#include <errno.h> #include <string.h> GL_TRY { // block of code // exception if (errno!=0) GL_THROW("Error condition %d: %s", errno, strerror(errno)); // more code } GL_CATCH(char *msg) { // exception handler } GL_ENDCATCH;
Note: it is ok to use GL_THROW inside a C++ catch statement. This behavior is defined (unlike using C++ throw inside C++ catch) because GL_THROW is implemented using longjmp().
See Exception handling for detail on the message format conventions.
Defines | |
| #define | GL_CATCH(Msg) } else {Msg = (*callback->exception.exception_msg)(); |
The argument msg provides access to the exception message thrown. | |
| #define | GL_ENDCATCH } (*callback->exception.delete_exception_handler)(_handler);} |
| GL_CATCH(Msg) blocks must always be terminated by a GL_ENDCATCH statement. | |
| #define | GL_THROW (*callback->exception.throw_exception) |
| The behavior of GL_THROW(Msg,. | |
| #define | GL_TRY { EXCEPTIONHANDLER *_handler = (*callback->exception.create_exception_handler)(); if (_handler==NULL) (*callback->output_error)("%s(%d): module exception handler creation failed",__FILE__,__LINE__); else if (setjmp(_handler->buf)==0) { |
| You may create your own GL_TRY block and throw exception using GL_THROW(Msg,. | |
| #define GL_CATCH | ( | Msg | ) | } else {Msg = (*callback->exception.exception_msg)(); |
The argument msg provides access to the exception message thrown.
Otherwise, GL_CATCH(Msg) blocks function like all other code blocks.
The behavior of GL_THROW(Msg) is not defined inside GL_CATCH(Msg) blocks.
GL_CATCH blocks must always be terminated by a GL_ENDCATCH statement.
Definition at line 223 of file gridlabd.h.
| #define GL_THROW (*callback->exception.throw_exception) |
The behavior of GL_THROW(Msg,.
..) differs depending on the situation:
Definition at line 215 of file gridlabd.h.
Referenced by house_e::attach(), capacitor::capacitor(), comm::comm(), house::house(), house_e::house_e(), waterheater::init(), house_e::init(), house::init(), fuse::init(), plc::init(), inverter::init(), diesel_dg::init(), battery::init(), init_capacitor(), init_link(), init_load(), init_node(), init_powerflow_library(), init_powerflow_object(), init_pqload(), init_regulator(), init_relay(), init_series_reactor(), init_switch(), init_transformer(), init_triplex_node(), link::link(), meter::meter(), node::NR_populate(), plc::plc(), waterheater::presync(), house_e::presync(), substation::substation(), battery::sync(), climate::sync(), sync_capacitor(), sync_link(), sync_load(), sync_powerflow_library(), sync_powerflow_object(), sync_pqload(), sync_regulator(), sync_relay(), sync_series_reactor(), sync_switch(), sync_transformer(), sync_triplex_node(), and waterheater::waterheater().
| #define GL_TRY { EXCEPTIONHANDLER *_handler = (*callback->exception.create_exception_handler)(); if (_handler==NULL) (*callback->output_error)("%s(%d): module exception handler creation failed",__FILE__,__LINE__); else if (setjmp(_handler->buf)==0) { |
You may create your own GL_TRY block and throw exception using GL_THROW(Msg,.
..) within the block. Declaring this block will change the behavior of GL_THROW(Msg,...) only within the block. Calls to GL_THROW(Msg,...) within this try block will be transfer control to the GL_CATCH(Msg) block.
Definition at line 205 of file gridlabd.h.