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 /unoxml | |
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 'unoxml')
-rw-r--r-- | unoxml/source/rdf/librdf_repository.cxx | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/unoxml/source/rdf/librdf_repository.cxx b/unoxml/source/rdf/librdf_repository.cxx index 57428c002823..cb85f43ec47b 100644 --- a/unoxml/source/rdf/librdf_repository.cxx +++ b/unoxml/source/rdf/librdf_repository.cxx @@ -55,6 +55,7 @@ #include <rtl/ref.hxx> #include <rtl/ustring.hxx> #include <osl/diagnose.h> +#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/basemutex.hxx> #include <cppuhelper/supportsservice.hxx> @@ -721,8 +722,10 @@ void SAL_CALL librdf_NamedGraph::clear() const OUString contextU( m_xName->getStringValue() ); try { m_pRep->clearGraph_NoLock(contextU); - } catch (lang::IllegalArgumentException &) { - throw uno::RuntimeException(); + } catch (lang::IllegalArgumentException & ex) { + css::uno::Any anyEx = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException( ex.Message, + *this, anyEx ); } } @@ -850,10 +853,11 @@ uno::Reference< rdf::XBlankNode > SAL_CALL librdf_Repository::createBlankNode() reinterpret_cast<const char *>(id))); try { return rdf::BlankNode::create(m_xContext, nodeID); - } catch (const lang::IllegalArgumentException & iae) { + } catch (const lang::IllegalArgumentException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_Repository::createBlankNode: " - "illegal blank node label", *this, uno::makeAny(iae)); + "illegal blank node label", *this, anyEx); } } @@ -1456,10 +1460,11 @@ void SAL_CALL librdf_Repository::setStatementRDFa( xContent.set(rdf::Literal::create(m_xContext, content), uno::UNO_QUERY_THROW); } - } catch (const lang::IllegalArgumentException & iae) { + } catch (const lang::IllegalArgumentException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_Repository::setStatementRDFa: " - "cannot create literal", *this, uno::makeAny(iae)); + "cannot create literal", *this, anyEx); } std::shared_ptr<librdf_TypeConverter::Resource> const pSubject( @@ -1495,11 +1500,12 @@ void SAL_CALL librdf_Repository::setStatementRDFa( sContext, true); } } - catch (const container::NoSuchElementException& e) + catch (const container::NoSuchElementException&) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_Repository::setStatementRDFa: " - "cannot addStatementGraph", *this, uno::makeAny(e)); + "cannot addStatementGraph", *this, anyEx); } } @@ -1539,10 +1545,11 @@ librdf_Repository::getStatementRDFa( try { xXmlId.set( rdf::URI::create(m_xContext, s_nsOOo + sXmlId), uno::UNO_QUERY_THROW); - } catch (const lang::IllegalArgumentException & iae) { + } catch (const lang::IllegalArgumentException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_Repository::getStatementRDFa: " - "cannot create URI for XML ID", *this, uno::makeAny(iae)); + "cannot create URI for XML ID", *this, anyEx); } ::std::vector< rdf::Statement > ret; @@ -1561,11 +1568,12 @@ librdf_Repository::getStatementRDFa( } } } - catch (const container::NoSuchElementException& e) + catch (const container::NoSuchElementException&) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_Repository::getStatementRDFa: " - "cannot getStatementsGraph", *this, uno::makeAny(e)); + "cannot getStatementsGraph", *this, anyEx); } ::osl::MutexGuard g(m_aMutex); // don't call i_x* with mutex locked @@ -2196,10 +2204,11 @@ librdf_TypeConverter::convertToXURI(librdf_uri* i_pURI) const RTL_TEXTENCODING_UTF8) ); try { return rdf::URI::create(m_xContext, uriU); - } catch (const lang::IllegalArgumentException & iae) { + } catch (const lang::IllegalArgumentException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_TypeConverter::convertToXURI: " - "illegal uri", m_rRep, uno::makeAny(iae)); + "illegal uri", m_rRep, anyEx); } } @@ -2238,10 +2247,11 @@ librdf_TypeConverter::convertToXResource(librdf_node* i_pNode) const try { return uno::Reference<rdf::XResource>( rdf::BlankNode::create(m_xContext, labelU), uno::UNO_QUERY); - } catch (const lang::IllegalArgumentException & iae) { + } catch (const lang::IllegalArgumentException &) { + css::uno::Any anyEx = cppu::getCaughtException(); throw lang::WrappedTargetRuntimeException( "librdf_TypeConverter::convertToXResource: " - "illegal blank node label", m_rRep, uno::makeAny(iae)); + "illegal blank node label", m_rRep, anyEx); } } else { return uno::Reference<rdf::XResource>(convertToXURI(i_pNode), |