xref: /trunk/main/cppuhelper/inc/cppuhelper/exc_hlp.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CPPUHELPER_EXC_HLP_HXX_
29 #define _CPPUHELPER_EXC_HLP_HXX_
30 
31 #include <com/sun/star/uno/Any.hxx>
32 
33 namespace cppu
34 {
35 
36 /** This function throws the exception given by rExc.  The given value has to
37     be of typeclass EXCEPTION and must be dervived from or of
38     type com.sun.star.uno.Exception.
39 
40     @param rExc
41            exception to be thrown.
42 */
43 void SAL_CALL throwException( const ::com::sun::star::uno::Any & rExc )
44     SAL_THROW( (::com::sun::star::uno::Exception) );
45 
46 /** Use this function to get the dynamic type of a caught C++-UNO exception;
47     completes the above function throwing exceptions generically.
48 
49     try
50     {
51         ...
52     }
53     catch (::com::sun::star::uno::RuntimeException &)
54     {
55         // you ought not handle RuntimeExceptions:
56         throw;
57     }
58     catch (::com::sun::star::uno::Exception &)
59     {
60         ::com::sun::star::uno::Any caught( ::cppu::getCaughtException() );
61         ...
62     }
63 
64     Restrictions:
65     - use only for caught C++-UNO exceptions (UNOIDL defined)
66     - only as first statement in a catch block!
67     - don't do a C++ rethrow (throw;) after you have called this function
68     - call getCaughtException() just once in your catch block!
69       (function internally uses a C++ rethrow)
70 
71     @return
72               caught UNO exception
73 
74     @attention Caution!
75               This function is limited to the same C++ compiler runtime library.
76               E.g. for MSVC, this means that the catch handler code (the one
77               that calls getCaughtException()) needs to use the very same
78               C++ runtime library, e.g. msvcrt.dll as cppuhelper, e.g.
79               cppuhelper3MSC.dll and the bridge library, e.g. msci_uno.dll.
80               This is the case if all of them are compiled with the same
81               compiler version.
82               Background: The msci_uno.dll gets a rethrown exception out
83               of the internal msvcrt.dll thread local storage (tls).
84               Thus you _must_ not use this function if your code needs to run
85               in newer UDK versions without being recompiled, because those
86               newer UDK (-> OOo versions) potentially use newer C++ runtime
87               libraries which most often become incompatible!
88 
89               But this function ought to be usable for most OOo internal C++-UNO
90               development, because the whole OOo code base is compiled using the
91               same C++ compiler (and linking against one runtime library).
92 */
93 ::com::sun::star::uno::Any SAL_CALL getCaughtException();
94 
95 }
96 
97 #endif
98 
99