summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-05-24 15:47:30 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-25 21:46:49 +0200
commit3a51daeace695ead38cfd82b3a0f1e6f25a32e0f (patch)
treeaf3ef1144aef6ed62f4ab99b88d13b41bd3b3694 /extensions
parentff3bdde2527123fc9e011ff0d93e958174632186 (diff)
Improve re-throwing of UNO exceptions
(*) if we are already throwing a Wrapped*Exception, get the exception using cppu::getCaughtexception. (*) when catching and then immediately throwing UNO exceptions, use cppu::getCaughtException to prevent exception slicing (*) if we are going to catch an exception and then immediately throw a RuntimeException, rather throw a WrappedTargetRuntimeException and preserve the original exception information. Change-Id: Ia7a501a50ae0e6f4d05186333c8517fdcb17d558 Reviewed-on: https://gerrit.libreoffice.org/54692 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'extensions')
-rw-r--r--extensions/source/ole/oleobjw.cxx64
-rw-r--r--extensions/source/update/feed/updatefeed.cxx29
2 files changed, 59 insertions, 34 deletions
diff --git a/extensions/source/ole/oleobjw.cxx b/extensions/source/ole/oleobjw.cxx
index 8238088e641f..73ef6bd60df1 100644
--- a/extensions/source/ole/oleobjw.cxx
+++ b/extensions/source/ole/oleobjw.cxx
@@ -29,11 +29,13 @@
#include <com/sun/star/script/CannotConvertException.hpp>
#include <com/sun/star/script/FailReason.hpp>
#include <com/sun/star/beans/XMaterialHolder.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/script/XInvocation.hpp>
#include <com/sun/star/bridge/ModelDependent.hpp>
#include <com/sun/star/bridge/oleautomation/NamedArgument.hpp>
#include <com/sun/star/bridge/oleautomation/PropertyPutArgument.hpp>
+#include <cppuhelper/exc_hlp.hxx>
#include <typelib/typedescription.hxx>
#include <rtl/uuid.h>
@@ -158,9 +160,11 @@ Any SAL_CALL IUnknownWrapper::invokeGetProperty( const OUString& aPropertyName,
}
catch ( const Exception& e )
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::invokeGetProperty ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::invokeGetProperty ! Message : \n " +
+ e.Message,
+ nullptr, anyEx );
}
return aResult;
}
@@ -186,9 +190,11 @@ Any SAL_CALL IUnknownWrapper::invokePutProperty( const OUString& aPropertyName,
}
catch ( const Exception& e )
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::invokePutProperty ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::invokePutProperty ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
return aResult;
}
@@ -241,9 +247,11 @@ Any SAL_CALL IUnknownWrapper::invoke( const OUString& aFunctionName,
}
catch (const Exception & e)
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::invoke ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::invoke ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
catch(...)
@@ -408,9 +416,11 @@ void SAL_CALL IUnknownWrapper::setValue( const OUString& aPropertyName,
}
catch (const Exception & e)
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::setValue ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::setValue ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
catch (...)
@@ -550,9 +560,11 @@ Any SAL_CALL IUnknownWrapper::getValue( const OUString& aPropertyName )
}
catch (const Exception & e)
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::getValue ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::getValue ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
catch (...)
{
@@ -599,9 +611,11 @@ sal_Bool SAL_CALL IUnknownWrapper::hasMethod( const OUString& aName )
}
catch (const Exception & e)
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::hasMethod ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::hasMethod ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
catch (...)
{
@@ -648,9 +662,11 @@ sal_Bool SAL_CALL IUnknownWrapper::hasProperty( const OUString& aName )
}
catch (const Exception & e)
{
- throw RuntimeException("[automation bridge] unexpected exception in "
- "IUnknownWrapper::hasProperty ! Message : \n" +
- e.Message);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException("[automation bridge] unexpected exception in "
+ "IUnknownWrapper::hasProperty ! Message : \n" +
+ e.Message,
+ nullptr, anyEx );
}
catch (...)
@@ -1211,8 +1227,10 @@ void SAL_CALL IUnknownWrapper::initialize( const Sequence< Any >& aArguments )
}
catch( const Exception& e )
{
- throw RuntimeException(
- "[automation bridge] unexpected exception in IUnknownWrapper::initialize() error message: \n" + e.Message );
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "[automation bridge] unexpected exception in IUnknownWrapper::initialize() error message: \n" + e.Message,
+ nullptr, anyEx );
}
}
}
diff --git a/extensions/source/update/feed/updatefeed.cxx b/extensions/source/update/feed/updatefeed.cxx
index e42f064d156f..6998da2f941b 100644
--- a/extensions/source/update/feed/updatefeed.cxx
+++ b/extensions/source/update/feed/updatefeed.cxx
@@ -19,6 +19,7 @@
#include <config_folders.h>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -255,17 +256,23 @@ public:
return uno::makeAny(aEntry);
}
-
- // action has been aborted
- catch( ucb::CommandAbortedException const & e)
- { throw lang::WrappedTargetException( "Command aborted", *this, uno::makeAny(e) ); }
-
- // let runtime exception pass
- catch( uno::RuntimeException const & ) { throw; }
-
- // document not accessible
- catch( uno::Exception const & e)
- { throw lang::WrappedTargetException( "Document not accessible", *this, uno::makeAny(e) ); }
+ catch( ucb::CommandAbortedException const &)
+ {
+ // action has been aborted
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw lang::WrappedTargetException( "Command aborted", *this, anyEx );
+ }
+ catch( uno::RuntimeException const & )
+ {
+ // let runtime exception pass
+ throw;
+ }
+ catch( uno::Exception const &)
+ {
+ // document not accessible
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw lang::WrappedTargetException( "Document not accessible", *this, anyEx );
+ }
}
private: