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