diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-24 15:47:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-25 21:46:49 +0200 |
commit | 3a51daeace695ead38cfd82b3a0f1e6f25a32e0f (patch) | |
tree | af3ef1144aef6ed62f4ab99b88d13b41bd3b3694 /embeddedobj/source | |
parent | ff3bdde2527123fc9e011ff0d93e958174632186 (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 'embeddedobj/source')
-rw-r--r-- | embeddedobj/source/commonembedding/embedobj.cxx | 6 | ||||
-rw-r--r-- | embeddedobj/source/commonembedding/persistence.cxx | 5 | ||||
-rw-r--r-- | embeddedobj/source/msole/oleembed.cxx | 14 |
3 files changed, 17 insertions, 8 deletions
diff --git a/embeddedobj/source/commonembedding/embedobj.cxx b/embeddedobj/source/commonembedding/embedobj.cxx index 5eb943273fdf..8ec68838800f 100644 --- a/embeddedobj/source/commonembedding/embedobj.cxx +++ b/embeddedobj/source/commonembedding/embedobj.cxx @@ -38,6 +38,7 @@ #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/embed/EmbedMisc.hpp> +#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <comphelper/lok.hxx> @@ -100,12 +101,13 @@ void OCommonEmbeddedObject::Deactivate() catch( const embed::ObjectSaveVetoException& ) { } - catch( const uno::Exception& e ) + catch( const uno::Exception& ) { + css::uno::Any anyEx = cppu::getCaughtException(); throw embed::StorageWrappedTargetException( "The client could not store the object!", static_cast< ::cppu::OWeakObject* >( this ), - uno::makeAny( e ) ); + anyEx ); } } diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx index e8eaee6d59eb..999ccd28955d 100644 --- a/embeddedobj/source/commonembedding/persistence.cxx +++ b/embeddedobj/source/commonembedding/persistence.cxx @@ -138,12 +138,13 @@ uno::Reference< io::XInputStream > createTempInpStreamFromStor( try { xStorage->copyToStorage( xTempStorage ); - } catch( const uno::Exception& e ) + } catch( const uno::Exception& ) { + css::uno::Any anyEx = cppu::getCaughtException(); throw embed::StorageWrappedTargetException( "Can't copy storage!", uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); + anyEx ); } try { diff --git a/embeddedobj/source/msole/oleembed.cxx b/embeddedobj/source/msole/oleembed.cxx index 64d95c3d7a56..e9078734d2a9 100644 --- a/embeddedobj/source/msole/oleembed.cxx +++ b/embeddedobj/source/msole/oleembed.cxx @@ -33,6 +33,7 @@ #include <com/sun/star/io/TempFile.hpp> #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/frame/XLoadable.hpp> @@ -43,6 +44,7 @@ #include <com/sun/star/system/SystemShellExecute.hpp> #include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/interfacecontainer.h> #include <comphelper/processfactory.hxx> #include <comphelper/mimeconfighelper.hxx> @@ -382,14 +384,16 @@ bool OleEmbeddedObject::TryToConvertToOOo( const uno::Reference< io::XStream >& m_xParentStorage->removeElement( m_aEntryName ); m_xParentStorage->renameElement( aTmpStreamName, m_aEntryName ); } - catch ( const uno::Exception& ) + catch ( const uno::Exception& ex ) { + css::uno::Any anyEx = cppu::getCaughtException(); try { close( true ); } catch( const uno::Exception& ) {} m_xParentStorage->dispose(); // ??? the storage has information loss, it should be closed without committing! - throw uno::RuntimeException(); // the repairing is not possible + throw css::lang::WrappedTargetRuntimeException( ex.Message, + nullptr, anyEx ); // the repairing is not possible } SAL_FALLTHROUGH; case 2: @@ -398,13 +402,15 @@ bool OleEmbeddedObject::TryToConvertToOOo( const uno::Reference< io::XStream >& m_xObjectStream = m_xParentStorage->openStreamElement( m_aEntryName, m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE ); m_nObjectState = embed::EmbedStates::LOADED; } - catch( const uno::Exception& ) + catch( const uno::Exception& ex ) { + css::uno::Any anyEx = cppu::getCaughtException(); try { close( true ); } catch( const uno::Exception& ) {} - throw uno::RuntimeException(); // the repairing is not possible + throw css::lang::WrappedTargetRuntimeException( ex.Message, + nullptr, anyEx ); // the repairing is not possible } SAL_FALLTHROUGH; |