00001 /* 00002 * AbiSource Program Utilities 00003 * Copyright (C) 2001 Dom Lachowicz <dominicl@seas.upenn.edu> 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program 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 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00018 * 02110-1301 USA. 00019 */ 00020 00021 #ifndef UT_EXCEPTION_H 00022 #define UT_EXCEPTION_H 00023 00024 /* pre-emptive dismissal; ut_types.h is needed by just about everything, 00025 * so even if it's commented out in-file that's still a lot of work for 00026 * the preprocessor to do... 00027 */ 00028 #ifndef UT_TYPES_H 00029 #include "ut_types.h" 00030 #endif 00031 00032 // 00033 // I really want AbiWord to start using exceptions as soon as is possible 00034 // but there might be platforms/compilers that are brain-dead and don't 00035 // support exceptions as such yet, which really sucks. So this file 00036 // provides a wrapper around standard C++ exception handling and offers 00037 // a do-nothing fall-back on platforms where exceptions aren't handled. 00038 // The idea is that the fall-back code goes away once we verify that every 00039 // platform supports exceptions. 00040 // '/me crosses his fingers' 00041 // 00042 // For starters, this should only initially be used in constructors 00043 // where we can't return an error-code (and thus have our code work 00044 // on both older and newer compilers via a UT_Error code). You can throw 00045 // from inside of a constructor, so we can potentially catch errors there 00046 // and verify which platforms support exceptions with 0 side-effects 00047 // to those platforms where exceptions aren't supported. So those people 00048 // with good compilers are now better off, and those with older, non-compliant 00049 // ones are no worse off than before, and that's not too bad because they 00050 // can't possibly do anything better/else anyway. 00051 // 00052 // -DAL- 00053 // 00054 00055 /* 00056 * Public base-class which all of our own 00057 * exceptions should inherit from 00058 */ 00059 class ABI_EXPORT UT_Exception 00060 { 00061 public: 00062 UT_Exception () {} 00063 virtual ~UT_Exception () {} 00064 }; 00065 00066 // 00067 // UT_TRY will begin a 'try' block 00068 // UT_CATCH will 'catch' a specific exception type 00069 // UT_END_CATCH evaluates to nothing, basically, but use it 00070 // after each UT_CATCH under penalty of death 00071 // UT_THROW will throw a new exception 00072 // UT_CATCH_ANY will catch anything (...) 00073 // UT_THROWS will declare a C++ method as throwing an exception 00074 // usage: 00075 // UT_THROWS((MyException1, MyException2)) 00076 // UT_RETHROW will rethrow a caught exception from within the 00077 // exception handler 00078 // 00079 00080 #ifdef ABI_DOESNT_SUPPORT_EXCEPTIONS 00081 00082 // d'oh! please list platforms/compilers here which have 00083 // issues with exceptions here for future reference 00084 00085 // MSVC5: has issues with Class::method() throw(ex) 00086 00087 // btw, this is nasty-as-shit for a reason - 00088 // 1) first off, what i'm doing is just plain ugly 00089 // 2) secondly, the preprocessor can't spit-out other preprocessor codes 00090 // so we can't use an #if 0 ... #endif construct, which would be nicer/prettier 00091 00092 #define UT_TRY 00093 #define UT_CATCH(x) if(false) { \ 00094 x; 00095 #define UT_END_CATCH } 00096 #define UT_THROW(x) (void)0 00097 #define UT_CATCH_ANY (void)0 00098 #define UT_RETHROW (void)0 00099 00100 #else 00101 00102 // yay, this platform supports exceptions 00103 00104 #define UT_TRY try 00105 #define UT_CATCH(x) catch(x) 00106 #define UT_END_CATCH 00107 #define UT_THROW(x) throw(x) 00108 #define UT_CATCH_ANY ... 00109 #define UT_RETHROW throw 00110 00111 #endif 00112 00113 // yeah, so 99.9999/100 C++ compilers don't handle this properly. shucks. 00114 // #define UT_THROWS(x) throw x 00115 #define UT_THROWS(x) 00116 00117 #endif /* UT_EXCEPTION_H */