xref: /trunk/main/cppuhelper/inc/cppuhelper/exc_hlp.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 #include "cppuhelper/cppuhelperdllapi.h"
30 
31 namespace cppu
32 {
33 
34 /** This function throws the exception given by rExc.  The given value has to
35     be of typeclass EXCEPTION and must be dervived from or of
36     type com.sun.star.uno.Exception.
37 
38     @param rExc
39            exception to be thrown.
40 */
41 CPPUHELPER_DLLPUBLIC void SAL_CALL throwException( const ::com::sun::star::uno::Any & rExc );
42 
43 /** Use this function to get the dynamic type of a caught C++-UNO exception;
44     completes the above function throwing exceptions generically.
45 
46     try
47     {
48         ...
49     }
50     catch (::com::sun::star::uno::RuntimeException &)
51     {
52         // you ought not handle RuntimeExceptions:
53         throw;
54     }
55     catch (::com::sun::star::uno::Exception &)
56     {
57         ::com::sun::star::uno::Any caught( ::cppu::getCaughtException() );
58         ...
59     }
60 
61     Restrictions:
62     - use only for caught C++-UNO exceptions (UNOIDL defined)
63     - only as first statement in a catch block!
64     - don't do a C++ rethrow (throw;) after you have called this function
65     - call getCaughtException() just once in your catch block!
66       (function internally uses a C++ rethrow)
67 
68     @return
69               caught UNO exception
70 
71     @attention Caution!
72               This function is limited to the same C++ compiler runtime library.
73               E.g. for MSVC, this means that the catch handler code (the one
74               that calls getCaughtException()) needs to use the very same
75               C++ runtime library, e.g. msvcrt.dll as cppuhelper, e.g.
76               cppuhelper3MSC.dll and the bridge library, e.g. msci_uno.dll.
77               This is the case if all of them are compiled with the same
78               compiler version.
79               Background: The msci_uno.dll gets a rethrown exception out
80               of the internal msvcrt.dll thread local storage (tls).
81               Thus you _must_ not use this function if your code needs to run
82               in newer UDK versions without being recompiled, because those
83               newer UDK (-> OOo versions) potentially use newer C++ runtime
84               libraries which most often become incompatible!
85 
86               But this function ought to be usable for most OOo internal C++-UNO
87               development, because the whole OOo code base is compiled using the
88               same C++ compiler (and linking against one runtime library).
89 */
90 CPPUHELPER_DLLPUBLIC ::com::sun::star::uno::Any SAL_CALL getCaughtException();
91 
92 }
93 
94 #endif
95