Exception handling
[Runtime module API]


Detailed Description

Module exception handling is provided for modules implemented in C to perform exception handling, as well to allow C++ code to throw exceptions to the core's main exception handler.

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 Documentation

#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)

#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.


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy