From 3a51daeace695ead38cfd82b3a0f1e6f25a32e0f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 24 May 2018 15:47:30 +0200 Subject: 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 Reviewed-by: Noel Grandin --- embeddedobj/source/commonembedding/embedobj.cxx | 6 ++++-- embeddedobj/source/commonembedding/persistence.cxx | 5 +++-- embeddedobj/source/msole/oleembed.cxx | 14 ++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) (limited to 'embeddedobj') 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 #include +#include #include #include @@ -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 #include #include +#include #include #include #include @@ -43,6 +44,7 @@ #include #include +#include #include #include #include @@ -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; -- cgit