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 /framework | |
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 'framework')
-rw-r--r-- | framework/source/accelerators/storageholder.cxx | 17 | ||||
-rw-r--r-- | framework/source/fwe/xml/menuconfiguration.cxx | 21 | ||||
-rw-r--r-- | framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx | 7 |
3 files changed, 29 insertions, 16 deletions
diff --git a/framework/source/accelerators/storageholder.cxx b/framework/source/accelerators/storageholder.cxx index 1cf4ca98719d..99c67af297e0 100644 --- a/framework/source/accelerators/storageholder.cxx +++ b/framework/source/accelerators/storageholder.cxx @@ -383,7 +383,6 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openSubStorageWithFal { // a) try it first with user specified open mode // ignore errors ... but save it for later use! - css::uno::Exception exResult; try { css::uno::Reference< css::embed::XStorage > xSubStorage = xBaseStorage->openStorageElement(sSubStorage, eOpenMode); @@ -391,13 +390,19 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openSubStorageWithFal return xSubStorage; } catch(const css::uno::RuntimeException&) - { throw; } - catch(const css::uno::Exception& ex) - { exResult = ex; } + { + throw; + } + catch(const css::uno::Exception&) + { + // b) readonly already tried? => forward last error! + if ((eOpenMode & css::embed::ElementModes::WRITE) != css::embed::ElementModes::WRITE) // fallback possible ? + throw; + } - // b) readonly already tried? => forward last error! + // b) readonly already tried, throw error if ((eOpenMode & css::embed::ElementModes::WRITE) != css::embed::ElementModes::WRITE) // fallback possible ? - throw exResult; + throw css::uno::Exception(); // c) try it readonly // don't catch exception here! Outside code wish to know, if operation failed or not. diff --git a/framework/source/fwe/xml/menuconfiguration.cxx b/framework/source/fwe/xml/menuconfiguration.cxx index 1057119bc572..b4d8c7164c00 100644 --- a/framework/source/fwe/xml/menuconfiguration.cxx +++ b/framework/source/fwe/xml/menuconfiguration.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/xml/sax/Writer.hpp> #include <com/sun/star/io/IOException.hpp> #include <com/sun/star/io/XActiveDataSource.hpp> +#include <cppuhelper/exc_hlp.hxx> using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; @@ -80,20 +81,23 @@ Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML( } catch ( const RuntimeException& e ) { - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); } catch( const SAXException& e ) { + css::uno::Any anyEx = cppu::getCaughtException(); SAXException aWrappedSAXException; if ( !( e.WrappedException >>= aWrappedSAXException )) - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); else - throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() ); + throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), e.WrappedException ); } catch( const css::io::IOException& e ) { - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); } } @@ -111,15 +115,18 @@ void MenuConfiguration::StoreMenuBarConfigurationToXML( } catch ( const RuntimeException& e ) { - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); } catch ( const SAXException& e ) { - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); } catch ( const css::io::IOException& e ) { - throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw WrappedTargetException( e.Message, Reference< XInterface >(), anyEx ); } } diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx index 26e462495e16..229b5392b640 100644 --- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx +++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx @@ -51,6 +51,7 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/sequence.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/supportsservice.hxx> @@ -1022,12 +1023,12 @@ void SAL_CALL ModuleUIConfigurationManager::reset() impl_resetElementTypeData( rUserElementType, rDefaultElementType, aRemoveEventNotifyContainer, aReplaceEventNotifyContainer ); rUserElementType.bModified = false; } - catch (const Exception& e) + catch (const Exception&) { - css::uno::Any a(e); + css::uno::Any anyEx = cppu::getCaughtException(); throw css::lang::WrappedTargetRuntimeException( "ModuleUIConfigurationManager::reset exception", - css::uno::Reference<css::uno::XInterface>(*this), a); + css::uno::Reference<css::uno::XInterface>(*this), anyEx); } } |