summaryrefslogtreecommitdiff
path: root/stoc/source/javavm/javavm.cxx
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/source/javavm/javavm.cxx
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/source/javavm/javavm.cxx')
-rw-r--r--stoc/source/javavm/javavm.cxx30
1 files changed, 18 insertions, 12 deletions
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 );
}
}