1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _CPPUHELPER_EXC_HLP_HXX_ 25 #define _CPPUHELPER_EXC_HLP_HXX_ 26 27 #include <com/sun/star/uno/Any.hxx> 28 29 namespace cppu 30 { 31 32 /** This function throws the exception given by rExc. The given value has to 33 be of typeclass EXCEPTION and must be dervived from or of 34 type com.sun.star.uno.Exception. 35 36 @param rExc 37 exception to be thrown. 38 */ 39 void SAL_CALL throwException( const ::com::sun::star::uno::Any & rExc ) 40 SAL_THROW( (::com::sun::star::uno::Exception) ); 41 42 /** Use this function to get the dynamic type of a caught C++-UNO exception; 43 completes the above function throwing exceptions generically. 44 45 try 46 { 47 ... 48 } 49 catch (::com::sun::star::uno::RuntimeException &) 50 { 51 // you ought not handle RuntimeExceptions: 52 throw; 53 } 54 catch (::com::sun::star::uno::Exception &) 55 { 56 ::com::sun::star::uno::Any caught( ::cppu::getCaughtException() ); 57 ... 58 } 59 60 Restrictions: 61 - use only for caught C++-UNO exceptions (UNOIDL defined) 62 - only as first statement in a catch block! 63 - don't do a C++ rethrow (throw;) after you have called this function 64 - call getCaughtException() just once in your catch block! 65 (function internally uses a C++ rethrow) 66 67 @return 68 caught UNO exception 69 70 @attention Caution! 71 This function is limited to the same C++ compiler runtime library. 72 E.g. for MSVC, this means that the catch handler code (the one 73 that calls getCaughtException()) needs to use the very same 74 C++ runtime library, e.g. msvcrt.dll as cppuhelper, e.g. 75 cppuhelper3MSC.dll and the bridge library, e.g. msci_uno.dll. 76 This is the case if all of them are compiled with the same 77 compiler version. 78 Background: The msci_uno.dll gets a rethrown exception out 79 of the internal msvcrt.dll thread local storage (tls). 80 Thus you _must_ not use this function if your code needs to run 81 in newer UDK versions without being recompiled, because those 82 newer UDK (-> OOo versions) potentially use newer C++ runtime 83 libraries which most often become incompatible! 84 85 But this function ought to be usable for most OOo internal C++-UNO 86 development, because the whole OOo code base is compiled using the 87 same C++ compiler (and linking against one runtime library). 88 */ 89 ::com::sun::star::uno::Any SAL_CALL getCaughtException(); 90 91 } 92 93 #endif 94 95