summaryrefslogtreecommitdiff
path: root/cppuhelper
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 /cppuhelper
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 'cppuhelper')
-rw-r--r--cppuhelper/source/component.cxx8
-rw-r--r--cppuhelper/source/implbase.cxx14
-rw-r--r--cppuhelper/source/propertysetmixin.cxx106
3 files changed, 76 insertions, 52 deletions
diff --git a/cppuhelper/source/component.cxx b/cppuhelper/source/component.cxx
index d906243bfddb..16cf56f257e6 100644
--- a/cppuhelper/source/component.cxx
+++ b/cppuhelper/source/component.cxx
@@ -20,8 +20,10 @@
#include <rtl/string.hxx>
#include <osl/diagnose.h>
#include <cppuhelper/component.hxx>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/typeprovider.hxx>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
using namespace osl;
@@ -189,8 +191,10 @@ void OComponentHelper::dispose()
}
catch (Exception & exc)
{
- throw RuntimeException(
- "unexpected UNO exception caught: " + exc.Message );
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw lang::WrappedTargetRuntimeException(
+ "unexpected UNO exception caught: " + exc.Message,
+ nullptr, anyEx );
}
}
else
diff --git a/cppuhelper/source/implbase.cxx b/cppuhelper/source/implbase.cxx
index b8bc91b769b1..f16c587431f0 100644
--- a/cppuhelper/source/implbase.cxx
+++ b/cppuhelper/source/implbase.cxx
@@ -18,11 +18,13 @@
*/
#include <cppuhelper/compbase_ex.hxx>
+#include <cppuhelper/exc_hlp.hxx>
#include <osl/diagnose.h>
#include <rtl/instance.hxx>
#include <rtl/string.hxx>
#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
using namespace ::osl;
@@ -120,8 +122,10 @@ void WeakComponentImplHelperBase::dispose()
}
catch (Exception & exc)
{
- throw RuntimeException(
- "unexpected UNO exception caught: " + exc.Message );
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw lang::WrappedTargetRuntimeException(
+ "unexpected UNO exception caught: " + exc.Message,
+ nullptr, anyEx );
}
}
}
@@ -244,8 +248,10 @@ void WeakAggComponentImplHelperBase::dispose()
}
catch (Exception & exc)
{
- throw RuntimeException(
- "unexpected UNO exception caught: " + exc.Message );
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw lang::WrappedTargetRuntimeException(
+ "unexpected UNO exception caught: " + exc.Message,
+ nullptr, anyEx );
}
}
}
diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx
index 8469f1a7c51d..88e104d90453 100644
--- a/cppuhelper/source/propertysetmixin.cxx
+++ b/cppuhelper/source/propertysetmixin.cxx
@@ -66,6 +66,7 @@
#include <com/sun/star/uno/TypeClass.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/XInterface.hpp>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/propertysetmixin.hxx>
#include <cppuhelper/weak.hxx>
@@ -436,9 +437,11 @@ PropertySetMixinImpl::Impl::Impl(
m_type.getTypeName()),
css::uno::UNO_QUERY_THROW);
} catch (css::container::NoSuchElementException & e) {
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"unexpected com.sun.star.container.NoSuchElementException: "
- + e.Message);
+ + e.Message,
+ nullptr, anyEx );
}
std::vector< rtl::OUString > handleNames;
initProperties(ifc, m_absentOptional, &handleNames);
@@ -509,10 +512,11 @@ void PropertySetMixinImpl::Impl::setProperty(
throw css::lang::IllegalArgumentException(
e.Message, object, illegalArgumentPosition);
} else {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
}
} catch (css::lang::IllegalAccessException &) {
//TODO Clarify whether PropertyVetoException is the correct exception
@@ -564,10 +568,11 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
try {
value = field->get(object->queryInterface(m_type));
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
} catch (css::lang::WrappedTargetRuntimeException & e) {
//FIXME A WrappedTargetRuntimeException from XIdlField2.get is not
// guaranteed to originate directly within XIdlField2.get (and thus have
@@ -621,10 +626,11 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
ambiguous->getField("Value"), css::uno::UNO_QUERY_THROW)->
get(value);
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
}
undoAmbiguous = false;
} else if (undoDefaulted
@@ -649,10 +655,11 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
defaulted->getField("Value"), css::uno::UNO_QUERY_THROW)->
get(value);
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
}
undoDefaulted = false;
} else if (undoOptional
@@ -681,10 +688,11 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty(
optional->getField("Value"), css::uno::UNO_QUERY_THROW)->
get(value);
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
}
undoOptional = false;
} else {
@@ -738,15 +746,17 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
type->getField("IsAmbiguous"), css::uno::UNO_QUERY_THROW)->set(
strct, css::uno::Any(isAmbiguous));
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
} catch (css::lang::IllegalAccessException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalAccessException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalAccessException: "
+ + e.Message,
+ object, anyEx );
}
return strct;
}
@@ -767,15 +777,17 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
type->getField("IsDefaulted"), css::uno::UNO_QUERY_THROW)->set(
strct, css::uno::Any(isDefaulted));
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
} catch (css::lang::IllegalAccessException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalAccessException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalAccessException: "
+ + e.Message,
+ object, anyEx );
}
return strct;
}
@@ -799,15 +811,17 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue(
isAmbiguous, wrapDefaulted, isDefaulted, false));
}
} catch (css::lang::IllegalArgumentException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalArgumentException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalArgumentException: "
+ + e.Message,
+ object, anyEx );
} catch (css::lang::IllegalAccessException & e) {
- throw css::uno::RuntimeException(
- ("unexpected com.sun.star.lang.IllegalAccessException: "
- + e.Message),
- object);
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "unexpected com.sun.star.lang.IllegalAccessException: "
+ + e.Message,
+ object, anyEx );
}
return strct;
}