Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/mevis/include/Inventor/SoCatch.h File Reference

Go to the source code of this file.

Classes

class  SoCatch
 Class containing static functions to control global exception handling for OpenInventor. More...

Defines

#define SO_CATCH_START   if (!SoCatch::isExceptionHandlingEnabled()) {
 See documentation of SO_CATCH_END.
#define SO_CATCH_ELSE(CODE_BEFORE_TRY)
 See documentation of SO_CATCH_END.
#define SO_CATCH_END(ERR_OBJ_TYPE_ID, OP_DESCR_STR, ACTION_TYPE_ID, END_STR)
 Third macro used after SO_CATCH_START, SO_CATCH_ELSE and SO_CATCH_END.

Define Documentation

#define SO_CATCH_ELSE (   CODE_BEFORE_TRY)
Value:
}                                  \
    else {                             \
      CODE_BEFORE_TRY                  \
      try {

CODE_BEFORE_TRY can be some initialization code or ";" done only in case of enabled exception handling directly before calling try; so some variables can be initialized from objects before these object are changed due to the execution which could cause the exception. For example a type could be read from an object before it's deleted. The type then can be used in SO_CATCH_END. See also SO_CATCH_END examples.

Definition at line 140 of file SoCatch.h.

#define SO_CATCH_END (   ERR_OBJ_TYPE_ID,
  OP_DESCR_STR,
  ACTION_TYPE_ID,
  END_STR 
)
Value:
}                                                       \
      catch(...) {                                            \
        /* Bad case, we caught a crash. Compose            */ \
        /* the error string and post it to SoError.        */ \
        try {                                                 \
          /* Do extra save message posting since we must   */ \
          /* assume that passed parameters (which could    */ \
          /* be expressions) also could be corrupt.        */ \
          SoCatch::postExceptionMessage(ERR_OBJ_TYPE_ID,      \
                                        OP_DESCR_STR,         \
                                        ACTION_TYPE_ID,       \
                                        END_STR);             \
        }                                                     \
        catch(...) {                                          \
          SoError::post("<Could not create error message "    \
                        "after catching fatal error>");       \
        }                                                     \
      } /* catch(...) */                                      \
    }

Usage: 1 SO_CATCH_START 2 <user_code> 3 SO_CATCH_ELSE(;) 4 <user_code> 5 SO_CATCH_END(ERR_OBJ_PTR, OP_DESCR_STR, ACTION_PTR, END_STR).

It is strongly recommended that <user code>=""> in line 2 and 4 is identical since only one of both will be executed dependent on whether exception handling is enabled or not.

Some code can be passed to SO_CATCH_ELSE in the case that the stuff passed to SO_CATCH_ELSE requires some parameters which need to be initialized outside the try body. If no code needs to be passed a ; can be used instead.

For a parameter description of this macro see SoCatch::postExceptionMessage();

Examples: myNodePtr is a pointer to a node of class SoMyNode. rednerActionPtr is a pointer to a SoGLRenderAction.

SO_CATCH_START

userCode

SO_CATCH_ELSE(;)

userCode

SO_CATCH_END(myNodePtr->getTypeId(), "applying", renderActionPtr->getTypeId(), "to it.")

would result in

"Crash in SoMyNode while applying SoGLRenderAction to it."

or

this is deleted and could cause an exception.

SO_CATCH_START

delete this;

SO_CATCH_ELSE(SoType myType=getTypeId();)

delete this;

SO_CATCH_END(myType, "deleting", SoType::badType(), "it.")

would result in

"Crash in SoMyType while deleting it."

In both cases eventually a list of most recently called and traced functions and/or the call stack of traced functions is printed as specified in the settings of the SoGlobalTraceBuffer instance.

Definition at line 210 of file SoCatch.h.

#define SO_CATCH_START   if (!SoCatch::isExceptionHandlingEnabled()) {

Definition at line 128 of file SoCatch.h.