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 /sfx2 | |
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 'sfx2')
-rw-r--r-- | sfx2/source/doc/DocumentMetadataAccess.cxx | 86 | ||||
-rw-r--r-- | sfx2/source/doc/SfxDocumentMetaData.cxx | 36 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 20 | ||||
-rw-r--r-- | sfx2/source/view/ipclient.cxx | 8 |
4 files changed, 92 insertions, 58 deletions
diff --git a/sfx2/source/doc/DocumentMetadataAccess.cxx b/sfx2/source/doc/DocumentMetadataAccess.cxx index ff6ad06ea6a7..b24edf6e184c 100644 --- a/sfx2/source/doc/DocumentMetadataAccess.cxx +++ b/sfx2/source/doc/DocumentMetadataAccess.cxx @@ -44,6 +44,7 @@ #include <unotools/mediadescriptor.hxx> #include <comphelper/sequence.hxx> #include <comphelper/storagehelper.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <sfx2/docfile.hxx> #include <sfx2/XmlIdRegistry.hxx> @@ -305,9 +306,10 @@ addFile(struct DocumentMetadataAccess_Impl const & i_rImpl, } } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( - "addFile: exception", /*this*/nullptr, uno::makeAny(e)); + "addFile: exception", /*this*/nullptr, anyEx); } } @@ -353,10 +355,11 @@ removeFile(struct DocumentMetadataAccess_Impl const & i_rImpl, getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), nullptr); } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "removeFile: exception", - nullptr, uno::makeAny(e)); + nullptr, anyEx); } } @@ -382,10 +385,11 @@ getAllParts(struct DocumentMetadataAccess_Impl const & i_rImpl) return ret; } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "getAllParts: exception", - nullptr, uno::makeAny(e)); + nullptr, anyEx); } } @@ -404,10 +408,11 @@ isPartOfType(struct DocumentMetadataAccess_Impl const & i_rImpl, return xEnum->hasMoreElements(); } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "isPartOfType: exception", - nullptr, uno::makeAny(e)); + nullptr, anyEx); } } @@ -577,10 +582,11 @@ retry: if (handleError(e, i_xHandler)) goto retry; } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "importFile: exception", - nullptr, uno::makeAny(e)); + nullptr, anyEx); } } @@ -735,10 +741,11 @@ static void init(struct DocumentMetadataAccess_Impl & i_rImpl) i_rImpl.m_xManifest->addStatement(i_rImpl.m_xBaseURI.get(), getURI<rdf::URIs::RDF_TYPE>(i_rImpl.m_xContext), getURI<rdf::URIs::PKG_DOCUMENT>(i_rImpl.m_xContext).get()); - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "init: unexpected exception", nullptr, - uno::makeAny(e)); + anyEx); } // add top-level content files @@ -898,10 +905,11 @@ DocumentMetadataAccess::addMetadataFile(const OUString & i_rFileName, try { m_pImpl->m_xRepository->createGraph(xGraphName); - } catch (const rdf::RepositoryException & e) { + } catch (const rdf::RepositoryException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "DocumentMetadataAccess::addMetadataFile: exception", - *this, uno::makeAny(e)); + *this, anyEx); // note: all other exceptions are propagated } @@ -940,10 +948,11 @@ DocumentMetadataAccess::importMetadataFile(::sal_Int16 i_Format, try { m_pImpl->m_xRepository->importGraph( i_Format, i_xInStream, xGraphName, i_xBaseURI); - } catch (const rdf::RepositoryException & e) { + } catch (const rdf::RepositoryException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "DocumentMetadataAccess::importMetadataFile: " - "RepositoryException", *this, uno::makeAny(e)); + "RepositoryException", *this, anyEx); // note: all other exceptions are propagated } @@ -958,10 +967,11 @@ DocumentMetadataAccess::removeMetadataFile( { try { m_pImpl->m_xRepository->destroyGraph(i_xGraphName); - } catch (const rdf::RepositoryException & e) { + } catch (const rdf::RepositoryException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "DocumentMetadataAccess::removeMetadataFile: " - "RepositoryException", *this, uno::makeAny(e)); + "RepositoryException", *this, anyEx); // note: all other exceptions are propagated } @@ -1017,10 +1027,11 @@ DocumentMetadataAccess::removeContentOrStylesFile( } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "DocumentMetadataAccess::removeContentOrStylesFile: exception", - *this, uno::makeAny(e)); + *this, anyEx); } } @@ -1113,10 +1124,11 @@ void SAL_CALL DocumentMetadataAccess::loadMetadataFromStorage( } } catch (const uno::RuntimeException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "DocumentMetadataAccess::loadMetadataFromStorage: " - "exception", *this, uno::makeAny(e)); + "exception", *this, anyEx); } for (const auto& aStgFile : StgFiles) @@ -1143,12 +1155,14 @@ void SAL_CALL DocumentMetadataAccess::storeMetadataToStorage( writeStream(*m_pImpl, i_xStorage, xManifest, s_manifest, baseURI); } catch (const uno::RuntimeException &) { throw; - } catch (const io::IOException & e) { + } catch (const io::IOException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetException( - "storeMetadataToStorage: IO exception", *this, uno::makeAny(e)); - } catch (const uno::Exception & e) { + "storeMetadataToStorage: IO exception", *this, anyEx); + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( - "storeMetadataToStorage: exception", *this, uno::makeAny(e)); + "storeMetadataToStorage: exception", *this, anyEx); } // export metadata streams @@ -1175,19 +1189,22 @@ void SAL_CALL DocumentMetadataAccess::storeMetadataToStorage( writeStream(*m_pImpl, i_xStorage, xName, relName, baseURI); } catch (const uno::RuntimeException &) { throw; - } catch (const io::IOException & e) { + } catch (const io::IOException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetException( "storeMetadataToStorage: IO exception", - *this, uno::makeAny(e)); - } catch (const uno::Exception & e) { + *this, anyEx); + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "storeMetadataToStorage: exception", - *this, uno::makeAny(e)); + *this, anyEx); } } - } catch (const rdf::RepositoryException & e) { + } catch (const rdf::RepositoryException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( - "storeMetadataToStorage: exception", *this, uno::makeAny(e)); + "storeMetadataToStorage: exception", *this, anyEx); } } @@ -1222,10 +1239,11 @@ DocumentMetadataAccess::loadMetadataFromMedium( throw; } catch (const io::IOException &) { throw; - } catch (const uno::Exception & e) { + } catch (const uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetException( "DocumentMetadataAccess::loadMetadataFromMedium: " - "exception", *this, uno::makeAny(e)); + "exception", *this, anyEx); } if (!xStorage.is()) { throw uno::RuntimeException( diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx index 7e696129ad78..1d808f67c5c3 100644 --- a/sfx2/source/doc/SfxDocumentMetaData.cxx +++ b/sfx2/source/doc/SfxDocumentMetaData.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <cppuhelper/compbase.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/lang/XInitialization.hpp> @@ -677,11 +678,11 @@ SfxDocumentMetaData::setMetaText(const char* i_name, xNode->appendChild(xTextNode); return true; } - } catch (const css::xml::dom::DOMException & e) { - css::uno::Any a(e); + } catch (const css::xml::dom::DOMException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "SfxDocumentMetaData::setMetaText: DOM exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } } @@ -808,11 +809,11 @@ SfxDocumentMetaData::setMetaList(const char* i_name, } return true; - } catch (const css::xml::dom::DOMException & e) { - css::uno::Any a(e); + } catch (const css::xml::dom::DOMException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "SfxDocumentMetaData::setMetaList: DOM exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } } @@ -947,11 +948,11 @@ SfxDocumentMetaData::updateElement(const char *i_name, m_xParent->appendChild(xNode); } m_meta[name] = xNode; - } catch (const css::xml::dom::DOMException & e) { - css::uno::Any a(e); + } catch (const css::xml::dom::DOMException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "SfxDocumentMetaData::updateElement: DOM exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } } @@ -1104,11 +1105,11 @@ void SfxDocumentMetaData::init( css::uno::UNO_QUERY_THROW); xRElem->appendChild(xParent); m_xParent = xParent; - } catch (const css::xml::dom::DOMException & e) { - css::uno::Any a(e); + } catch (const css::xml::dom::DOMException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "SfxDocumentMetaData::init: DOM exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } } @@ -1886,11 +1887,12 @@ SfxDocumentMetaData::loadFromMedium(const OUString & URL, throw; } catch (const css::io::IOException &) { throw; - } catch (const css::uno::Exception & e) { + } catch (const css::uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetException( "SfxDocumentMetaData::loadFromMedium: exception", css::uno::Reference<css::uno::XInterface>(*this), - css::uno::makeAny(e)); + anyEx); } if (!xStorage.is()) { throw css::uno::RuntimeException( @@ -2001,11 +2003,11 @@ SfxDocumentMetaData::createClone() pNew->init(xDoc); } catch (const css::uno::RuntimeException &) { throw; - } catch (const css::uno::Exception & e) { - css::uno::Any a(e); + } catch (const css::uno::Exception &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "SfxDocumentMetaData::createClone: exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } return css::uno::Reference<css::util::XCloneable> (pNew); } diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 752bec0ebc07..524b4f0b5b3d 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -2373,7 +2373,9 @@ void SAL_CALL SfxBaseModel::updateCmisProperties( const Sequence< document::Cmis } catch (const Exception & e) { - throw RuntimeException( e.Message, e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } @@ -2406,7 +2408,9 @@ void SAL_CALL SfxBaseModel::checkOut( ) } catch ( const Exception & e ) { - throw RuntimeException( e.Message, e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } } @@ -2430,7 +2434,9 @@ void SAL_CALL SfxBaseModel::cancelCheckOut( ) } catch ( const Exception & e ) { - throw RuntimeException( e.Message, e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } } @@ -2471,7 +2477,9 @@ void SAL_CALL SfxBaseModel::checkIn( sal_Bool bIsMajor, const OUString& rMessage } catch ( const Exception & e ) { - throw RuntimeException( e.Message, e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } } @@ -2493,7 +2501,9 @@ uno::Sequence< document::CmisVersion > SAL_CALL SfxBaseModel::getAllVersions( ) } catch ( const Exception & e ) { - throw RuntimeException( e.Message, e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } return aVersions; diff --git a/sfx2/source/view/ipclient.cxx b/sfx2/source/view/ipclient.cxx index 81d93b38f55b..d12c1ea3e109 100644 --- a/sfx2/source/view/ipclient.cxx +++ b/sfx2/source/view/ipclient.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/embed/XStateChangeListener.hpp> #include <com/sun/star/embed/StateChangeInProgressException.hpp> #include <com/sun/star/embed/XLinkageSupport.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/task/ErrorCodeIOException.hpp> #include <com/sun/star/task/StatusIndicatorFactory.hpp> @@ -63,6 +64,7 @@ #include <svl/rectitem.hxx> #include <svtools/soerr.hxx> #include <comphelper/processfactory.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <sfx2/lokhelper.hxx> @@ -371,9 +373,11 @@ uno::Reference< css::frame::XLayoutManager > SAL_CALL SfxInPlaceClient_Impl::get uno::Any aAny = xFrame->getPropertyValue( "LayoutManager" ); aAny >>= xMan; } - catch ( uno::Exception& ) + catch ( uno::Exception& ex ) { - throw uno::RuntimeException(); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( ex.Message, + nullptr, anyEx ); } return xMan; |