summaryrefslogtreecommitdiff
path: root/stoc
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 /stoc
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 'stoc')
-rw-r--r--stoc/source/implementationregistration/implreg.cxx8
-rw-r--r--stoc/source/invocation/invocation.cxx4
-rw-r--r--stoc/source/javaloader/javaloader.cxx7
-rw-r--r--stoc/source/javavm/javavm.cxx30
-rw-r--r--stoc/source/uriproc/UriReferenceFactory.cxx6
5 files changed, 37 insertions, 18 deletions
diff --git a/stoc/source/implementationregistration/implreg.cxx b/stoc/source/implementationregistration/implreg.cxx
index fd24918dd06d..7dff88085b57 100644
--- a/stoc/source/implementationregistration/implreg.cxx
+++ b/stoc/source/implementationregistration/implreg.cxx
@@ -21,6 +21,7 @@
#include <string.h>
#include <vector>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/implbase.hxx>
@@ -36,6 +37,7 @@
#include <rtl/ustrbuf.hxx>
#include <osl/process.h>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/loader/XImplementationLoader.hpp>
@@ -962,8 +964,10 @@ void insert_singletons(
}
catch (const container::NoSuchElementException & exc)
{
- throw RuntimeException(
- "cannot get service type description: " + exc.Message );
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "cannot get service type description: " + exc.Message,
+ nullptr, anyEx );
}
}
}
diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx
index 82dfbac5a417..1e4e54b297d5 100644
--- a/stoc/source/invocation/invocation.cxx
+++ b/stoc/source/invocation/invocation.cxx
@@ -19,6 +19,7 @@
#include <osl/mutex.hxx>
#include <cppuhelper/queryinterface.hxx>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/weak.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
@@ -562,9 +563,10 @@ void Invocation_Impl::setValue( const OUString& PropertyName, const Any& Value )
}
catch (const Exception & exc)
{
+ css::uno::Any anyEx = cppu::getCaughtException();
throw InvocationTargetException(
"exception occurred in setValue(): " + exc.Message,
- Reference< XInterface >(), makeAny( exc /* though sliced */ ) );
+ Reference< XInterface >(), anyEx );
}
}
}
diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx
index b51446c639fa..28aefc9fddf4 100644
--- a/stoc/source/javaloader/javaloader.cxx
+++ b/stoc/source/javaloader/javaloader.cxx
@@ -29,6 +29,8 @@
#include <uno/lbnames.h>
#include <uno/mapping.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <cppuhelper/exc_hlp.hxx>
#ifdef LINUX
#undef minor
@@ -252,7 +254,10 @@ const css::uno::Reference<XImplementationLoader> & JavaComponentLoader::getJavaL
}
catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
{
- throw RuntimeException("jvmaccess::VirtualMachine::AttachGuard::CreationException");
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
+ "jvmaccess::VirtualMachine::AttachGuard::CreationException",
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
// set the service manager at the javaloader
diff --git a/stoc/source/javavm/javavm.cxx b/stoc/source/javavm/javavm.cxx
index 6a6652390683..97167891c3e2 100644
--- a/stoc/source/javavm/javavm.cxx
+++ b/stoc/source/javavm/javavm.cxx
@@ -642,9 +642,10 @@ JavaVirtualMachine::initialize(css::uno::Sequence< css::uno::Any > const &
try {
m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(vm, nullptr);
} catch (jvmaccess::UnoVirtualMachine::CreationException &) {
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"jvmaccess::UnoVirtualMachine::CreationException",
- static_cast< cppu::OWeakObject * >(this));
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
}
}
@@ -870,9 +871,10 @@ JavaVirtualMachine::getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId)
jvmaccess::VirtualMachine::AttachGuard guard(m_xVirtualMachine);
setUpUnoVirtualMachine(guard.getEnvironment());
} catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &) {
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"jvmaccess::VirtualMachine::AttachGuard::CreationException occurred",
- static_cast< cppu::OWeakObject * >(this));
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
}
switch (returnType) {
@@ -961,10 +963,11 @@ void SAL_CALL JavaVirtualMachine::registerThread()
}
catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
{
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"JavaVirtualMachine::registerThread: jvmaccess::"
"VirtualMachine::AttachGuard::CreationException",
- static_cast< cppu::OWeakObject * >(this));
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
}
@@ -1234,9 +1237,10 @@ void SAL_CALL JavaVirtualMachine::elementReplaced(
}
catch (jvmaccess::VirtualMachine::AttachGuard::CreationException &)
{
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"jvmaccess::VirtualMachine::AttachGuard::CreationException",
- nullptr);
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
}
}
@@ -1476,9 +1480,10 @@ void JavaVirtualMachine::setUpUnoVirtualMachine(JNIEnv * environment) {
try {
baseUrl = exp->expandMacros("$URE_INTERNAL_JAVA_DIR/");
} catch (css::lang::IllegalArgumentException &) {
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"css::lang::IllegalArgumentException",
- static_cast< cppu::OWeakObject * >(this));
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
OUString classPath;
try {
@@ -1576,9 +1581,10 @@ void JavaVirtualMachine::setUpUnoVirtualMachine(JNIEnv * environment) {
m_xUnoVirtualMachine = new jvmaccess::UnoVirtualMachine(
m_xVirtualMachine, cl2);
} catch (jvmaccess::UnoVirtualMachine::CreationException &) {
- throw css::uno::RuntimeException(
+ css::uno::Any anyEx = cppu::getCaughtException();
+ throw css::lang::WrappedTargetRuntimeException(
"jvmaccess::UnoVirtualMachine::CreationException",
- static_cast< cppu::OWeakObject * >(this));
+ static_cast< cppu::OWeakObject * >(this), anyEx );
}
}
diff --git a/stoc/source/uriproc/UriReferenceFactory.cxx b/stoc/source/uriproc/UriReferenceFactory.cxx
index dc96323c1bb4..ac1178bb491d 100644
--- a/stoc/source/uriproc/UriReferenceFactory.cxx
+++ b/stoc/source/uriproc/UriReferenceFactory.cxx
@@ -39,6 +39,7 @@
#include <com/sun/star/uri/XUriReference.hpp>
#include <com/sun/star/uri/XUriReferenceFactory.hpp>
#include <com/sun/star/uri/XUriSchemeParser.hpp>
+#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weak.hxx>
@@ -350,11 +351,12 @@ css::uno::Reference< css::uri::XUriReference > Factory::parse(
serviceName, m_context);
} catch (css::uno::RuntimeException &) {
throw;
- } catch (const css::uno::Exception & e) {
+ } catch (const css::uno::Exception &) {
+ css::uno::Any anyEx = cppu::getCaughtException();
throw css::lang::WrappedTargetRuntimeException(
"creating service " + serviceName,
static_cast< cppu::OWeakObject * >(this),
- css::uno::makeAny(e)); //TODO: preserve type of e
+ anyEx);
}
if (service.is()) {
parser.set( service, css::uno::UNO_QUERY_THROW);