Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/mevis/include/Inventor/SoCatch.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2004 MeVis gGmbH  All Rights Reserved.
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  *
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: MeVis, Center for Medical Diagnostic Systems and
00027  *  Visualization GmbH, Universitätsallee 29, D-28359 Bremen, GERMANY, or:
00028  *
00029  *  http://www.mevis.de
00030  *
00031  */
00032 
00033 /*
00034  * Copyright (C) 2004   MeVis Research GmbH
00035  *
00036  _______________________________________________________________________
00037  _______________  M E V I S   R E S E A R C H   G M B H  _______________
00038  |
00039  |   Description:
00040  |   Macro file to implement exception handlers around some code to make
00041  |   code safe. In the case of caught exception an error message is composed
00042  |   and send to SoError.
00043  |   The usage of the exception handler is optional and can be enabled/disabled
00044  |   by the static class function SoCatch::enableExceptionHandling().
00045  |
00046  |   Author(s)      : Wolf Spindler, Felix Ritter
00047  |
00048  _______________  M E V I S   R E S E A R C H   G M B H  _______________
00049  _______________________________________________________________________
00050  */
00051 
00052 #ifndef  _SO_CATCH_
00053 #define  _SO_CATCH_
00054 
00055 #include <Inventor/system/SbSystem.h>
00056 #include <Inventor/misc/SoBasic.h>
00057 #include <Inventor/SbString.h>
00058 #include <Inventor/errors/SoError.h>
00059 
00066 
00067 class INVENTOR_API SoCatch
00068 {
00069    public:
00070 
00073       static SbBool isExceptionHandlingEnabled();
00074 
00077       static void enableExceptionHandling(SbBool on);
00078 
00080       static void initClass();
00081 
00112       static void postExceptionMessage(SoType      ERR_OBJ_TYPE_ID,
00113                                        const char *OP_DESCR_STR,
00114                                        SoType      ACTION_TYPE_ID,
00115                                        const char *END_STR);
00116 
00117    private:
00118 
00121       static SbBool _isExceptionHandlingEnabled;
00122 
00123 };
00124 
00125 #if !defined(DISABLE_ERRORTRACING)
00126 
00128 #define SO_CATCH_START \
00129     if (!SoCatch::isExceptionHandlingEnabled()) {
00130 
00131 
00140 #define SO_CATCH_ELSE(CODE_BEFORE_TRY) \
00141     }                                  \
00142     else {                             \
00143       CODE_BEFORE_TRY                  \
00144       try {
00145 
00146 
00210 #define SO_CATCH_END(ERR_OBJ_TYPE_ID, OP_DESCR_STR, ACTION_TYPE_ID, END_STR)    \
00211       }                                                       \
00212       catch(...) {                                            \
00213         /* Bad case, we caught a crash. Compose            */ \
00214         /* the error string and post it to SoError.        */ \
00215         try {                                                 \
00216           /* Do extra save message posting since we must   */ \
00217           /* assume that passed parameters (which could    */ \
00218           /* be expressions) also could be corrupt.        */ \
00219           SoCatch::postExceptionMessage(ERR_OBJ_TYPE_ID,      \
00220                                         OP_DESCR_STR,         \
00221                                         ACTION_TYPE_ID,       \
00222                                         END_STR);             \
00223         }                                                     \
00224         catch(...) {                                          \
00225           SoError::post("<Could not create error message "    \
00226                         "after catching fatal error>");       \
00227         }                                                     \
00228       } /* catch(...) */                                      \
00229     } /* else of SO_CATCH_ELSE */
00230 
00231 #else  // DISABLE_ERRORTRACING
00232 
00233 #define SO_CATCH_START \
00234     if(1) {
00235 #define SO_CATCH_ELSE(CODE_BEFORE_TRY) \
00236     }                                  \
00237     else {
00238 #define SO_CATCH_END(ERR_OBJ_TYPE_ID, OP_DESCR_STR, ACTION_TYPE_ID, END_STR) \
00239     }
00240 
00241 #endif  // DISABLE_ERRORTRACING
00242 
00243 #endif  // _SO_CATCH_