20#include <rtl/instance.hxx>
21#include <osl/diagnose.h>
23#include <uno/dispatcher.hxx>
24#include <uno/lbnames.h>
25#include <uno/mapping.hxx>
26#include <cppuhelper/detail/XExceptionThrower.hpp>
27#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
28#include <com/sun/star/ucb/NameClashException.hpp>
29#include <com/sun/star/uno/RuntimeException.hpp>
34using namespace ::
cppu;
41using cppuhelper::detail::XExceptionThrower;
44struct ExceptionThrower :
public uno_Interface, XExceptionThrower
48 virtual ~ExceptionThrower() {}
50 static Type const & getCppuType()
57 virtual void SAL_CALL acquire() noexcept override;
58 virtual
void SAL_CALL release() noexcept override;
62 virtual
void SAL_CALL rethrowException() override;
69void ExceptionThrower_acquire_release_nop(
70 SAL_UNUSED_PARAMETER uno_Interface * )
74void ExceptionThrower_dispatch(
76 void * pReturn,
void * pArgs [],
uno_Any ** ppException )
78 OSL_ASSERT( pMemberType->eTypeClass == typelib_TypeClass_INTERFACE_METHOD );
80 switch (
reinterpret_cast< typelib_InterfaceMemberTypeDescription *
>(
86 Type const & rType_demanded =
87 *
static_cast< Type const *
>( pArgs[ 0 ] );
89 rType_demanded.equals( ExceptionThrower::getCppuType() ))
92 TYPELIB_DANGER_GET( &pTD, rType_demanded.getTypeLibType() );
94 static_cast< uno_Any *
>( pReturn ), &pUnoI, pTD,
nullptr );
95 TYPELIB_DANGER_RELEASE( pTD );
100 static_cast< uno_Any *
>( pReturn ),
nullptr,
nullptr,
nullptr );
102 *ppException =
nullptr;
107 *ppException =
nullptr;
112 OSL_ASSERT( pAny->pType->eTypeClass == typelib_TypeClass_EXCEPTION );
121 *ppException, &exc,
cppu::UnoType<
decltype(exc)>::get().getTypeLibType(),
nullptr );
133 type.equals( ExceptionThrower::getCppuType() ))
135 XExceptionThrower * that =
this;
136 return Any( &that, type );
142void ExceptionThrower::acquire() noexcept
146void ExceptionThrower::release() noexcept
153 OSL_FAIL(
"unexpected!" );
158void ExceptionThrower::rethrowException()
164ExceptionThrower::ExceptionThrower()
166 uno_Interface::acquire = ExceptionThrower_acquire_release_nop;
167 uno_Interface::release = ExceptionThrower_acquire_release_nop;
168 uno_Interface::pDispatcher = ExceptionThrower_dispatch;
171#if defined(IOS) || defined(ANDROID) || defined(EMSCRIPTEN)
172#define RETHROW_FAKE_EXCEPTIONS 1
174#define RETHROW_FAKE_EXCEPTIONS 0
177class theExceptionThrower :
public rtl::Static<ExceptionThrower, theExceptionThrower> {};
179#if RETHROW_FAKE_EXCEPTIONS
198template <
class E>
void tryThrow(css::uno::Any
const& aException)
200 E aSpecificException;
201 if (aException >>= aSpecificException)
202 throw aSpecificException;
205void lo_mobile_throwException(css::uno::Any
const& aException)
207 assert(aException.getValueTypeClass() == css::uno::TypeClass_EXCEPTION);
209 tryThrow<css::ucb::InteractiveAugmentedIOException>(aException);
210 tryThrow<css::ucb::NameClashException>(aException);
211 tryThrow<css::uno::RuntimeException>(aException);
213 SAL_WARN(
"cppuhelper",
"lo_mobile_throwException: Unhandled exception type: " << aException.getValueTypeName());
228 if (exc.getValueTypeClass() != TypeClass_EXCEPTION)
231 "no UNO exception given "
232 "(must be derived from com::sun::star::uno::Exception)!" );
235#if RETHROW_FAKE_EXCEPTIONS
236 lo_mobile_throwException(exc);
242 "cannot get binary UNO to C++ mapping!" );
245 Reference< XExceptionThrower > xThrower;
246 uno2cpp.mapInterface(
247 reinterpret_cast< void **
>( &xThrower ),
248 static_cast< uno_Interface *
>( &theExceptionThrower::get() ),
249 ExceptionThrower::getCppuType() );
250 OSL_ASSERT( xThrower.is() );
251 xThrower->throwException( exc );
259#if defined(ANDROID) || defined(EMSCRIPTEN)
266 "cannot get C++ to binary UNO mapping!" );
272 "cannot get binary UNO to C++ mapping!" );
277 &pTD, ExceptionThrower::getCppuType().getTypeLibType() );
279 UnoInterfaceReference unoI;
280 cpp2uno.mapInterface(
281 reinterpret_cast< void **
>( &unoI.m_pUnoI ),
282 static_cast< XExceptionThrower *
>( &theExceptionThrower::get() ), pTD );
283 OSL_ASSERT( unoI.is() );
288 reinterpret_cast< typelib_InterfaceTypeDescription *
>( pTD )->
293 unoI.dispatch( pMemberTD,
nullptr,
nullptr, &exc );
295 TYPELIB_DANGER_RELEASE( pMemberTD );
296 TYPELIB_DANGER_RELEASE( pTD );
306 &ret, exc->pData, exc->pType, uno2cpp.get() );
void SAL_CALL uno_type_any_constructAndConvert(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_type_any_construct(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_AcquireFunc acquire) SAL_THROW_EXTERN_C()
css::uno::Type const & get()
#define SAL_WARN(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
void SAL_CALL throwException(Any const &exc)
Any SAL_CALL getCaughtException()
Use this function to get the dynamic type of a caught C++-UNO exception; completes the above function...