Open Inventor Reference
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...
 

Macros

#define SO_CATCH_START    if (!SoCatch::isExceptionHandlingEnabled()) {
 See documentation of SO_CATCH_END. More...
 
#define SO_CATCH_ELSE(CODE_BEFORE_TRY)
 See documentation of SO_CATCH_END. More...
 
#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. More...
 

Macro Definition Documentation

◆ SO_CATCH_ELSE

#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 91 of file SoCatch.h.

◆ SO_CATCH_END

#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. */ \
OP_DESCR_STR, \
ACTION_TYPE_ID, \
END_STR); \
} \
catch(...) { \
SoError::post("<Could not create error message " \
"after catching fatal error>"); \
} \
} /* catch(...) */ \
} /* else of SO_CATCH_ELSE */
static void postExceptionMessage(SoType ERR_OBJ_TYPE_ID, const char *OP_DESCR_STR, SoType ACTION_TYPE_ID, const char *END_STR)
Posts composed error message.
static void post(const char *formatString ...)
Posts an error.

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 161 of file SoCatch.h.

◆ SO_CATCH_START

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

Definition at line 79 of file SoCatch.h.