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): 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 213 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 205 of file gridlabd.h.
Referenced by waterheater::actual_Q(), capacitor::capacitor(), capbank::capbank(), climate::climate(), clotheswasher::clotheswasher(), comm::comm(), diesel_dg::diesel_dg(), dishwasher::dishwasher(), fuse::fuse(), generator::generator(), house::house(), plc::init(), init_capacitor(), init_fuse(), init_line(), init_link(), init_load(), init_meter(), init_node(), init_overhead_line(), init_powerflow_object(), init_regulator(), init_relay(), init_transformer(), init_triplex_line(), init_triplex_node(), init_underground_line(), lights::lights(), line::line(), line_configuration::line_configuration(), line_spacing::line_spacing(), link::link(), load::load(), meter::meter(), microwave::microwave(), multizone::multizone(), node::node(), occupantload::occupantload(), overhead_line::overhead_line(), overhead_line_conductor::overhead_line_conductor(), plc::plc(), plugload::plugload(), powerflow_object::powerflow_object(), range::range(), refrigerator::refrigerator(), regulator::regulator(), regulator_configuration::regulator_configuration(), relay::relay(), house::sync(), sync_capacitor(), sync_diesel_dg(), sync_fuse(), sync_line(), sync_link(), sync_load(), sync_meter(), sync_multizone(), sync_overhead_line(), sync_powerflow_object(), sync_regulator(), sync_relay(), sync_transformer(), sync_triplex_line(), sync_triplex_node(), sync_underground_line(), transformer::transformer(), transformer_configuration::transformer_configuration(), triplex_line::triplex_line(), triplex_line_conductor::triplex_line_conductor(), triplex_line_configuration::triplex_line_configuration(), triplex_node::triplex_node(), underground_line::underground_line(), underground_line_conductor::underground_line_conductor(), waterheater::update_T_and_or_h(), and waterheater::waterheater().
| #define GL_TRY { EXCEPTIONHANDLER *_handler = (*callback->exception.create_exception_handler)(); if (_handler==NULL) (*callback->output_error)("%s(%d): 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 199 of file gridlabd.h.