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 /connectivity | |
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 'connectivity')
13 files changed, 57 insertions, 16 deletions
diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx index 90f62bdc526f..056b287aa994 100644 --- a/connectivity/source/drivers/dbase/DTables.cxx +++ b/connectivity/source/drivers/dbase/DTables.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <dbase/DCatalog.hxx> #include <comphelper/types.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <strings.hrc> #include <connectivity/dbexception.hxx> @@ -85,9 +86,10 @@ sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const R { throw; } - catch(Exception&) + catch(Exception& ex) { - throw SQLException(); + css::uno::Any anyEx = cppu::getCaughtException(); + throw SQLException( ex.Message, nullptr, "", 0, anyEx ); } } } diff --git a/connectivity/source/drivers/hsqldb/HConnection.cxx b/connectivity/source/drivers/hsqldb/HConnection.cxx index cf4cafbe347c..7da46daafb2f 100644 --- a/connectivity/source/drivers/hsqldb/HConnection.cxx +++ b/connectivity/source/drivers/hsqldb/HConnection.cxx @@ -231,9 +231,10 @@ namespace connectivity { namespace hsqldb catch( const RuntimeException& ) { throw; } catch( const Exception& ) { + css::uno::Any anyEx = cppu::getCaughtException(); ::connectivity::SharedResources aResources; const OUString sError( aResources.getResourceString(STR_NO_TABLE_CONTAINER)); - throw WrappedTargetException( sError ,*this, ::cppu::getCaughtException() ); + throw WrappedTargetException( sError ,*this, anyEx ); } SAL_WARN_IF( !xTables.is(), "connectivity.hsqldb", "OHsqlConnection::impl_getTableContainer_throw: post condition not met!" ); diff --git a/connectivity/source/drivers/jdbc/JConnection.cxx b/connectivity/source/drivers/jdbc/JConnection.cxx index 5fdc586cc038..bfaef457d35e 100644 --- a/connectivity/source/drivers/jdbc/JConnection.cxx +++ b/connectivity/source/drivers/jdbc/JConnection.cxx @@ -39,6 +39,7 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <jvmaccess/classpath.hxx> #include <comphelper/namedvaluecollection.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <rtl/ustrbuf.hxx> #include <jni.h> #include <strings.hrc> @@ -688,15 +689,15 @@ void java_sql_Connection::loadDriverFromProperties( const OUString& _sDriverClas } } } - catch( const SQLException& e ) + catch( const SQLException& ) { + css::uno::Any anyEx = cppu::getCaughtException(); throw SQLException( lcl_getDriverLoadErrorMessage( getResources(),_sDriverClass, _sDriverClassPath ), *this, OUString(), 1000, - makeAny(e) - ); + anyEx); } catch( Exception& ) { diff --git a/connectivity/source/drivers/jdbc/Object.cxx b/connectivity/source/drivers/jdbc/Object.cxx index 20edd90d6192..4a9a854d48f7 100644 --- a/connectivity/source/drivers/jdbc/Object.cxx +++ b/connectivity/source/drivers/jdbc/Object.cxx @@ -28,6 +28,7 @@ #include <strings.hxx> #include <comphelper/logging.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <memory> @@ -222,7 +223,9 @@ void java_lang_Object::ThrowRuntimeException( JNIEnv* _pEnvironment, const Refer } catch (const SQLException& e) { - throw WrappedTargetRuntimeException(e.Message, e.Context, makeAny(e)); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } } diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx index 707d634044ce..180ded29a0b8 100644 --- a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx @@ -37,11 +37,13 @@ #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> +#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> #include "pq_xcolumns.hxx" @@ -331,7 +333,9 @@ void Columns::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + nullptr, anyEx ); } fire( RefreshedBroadcaster( *this ) ); } diff --git a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx index bab35147b26b..8501d84bea36 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexcolumns.cxx @@ -38,10 +38,12 @@ #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xcolumns.hxx" #include "pq_xindexcolumns.hxx" @@ -147,7 +149,9 @@ void IndexColumns::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.cxx b/connectivity/source/drivers/postgresql/pq_xindexes.cxx index 22b8acf7102c..70f35d515cc2 100644 --- a/connectivity/source/drivers/postgresql/pq_xindexes.cxx +++ b/connectivity/source/drivers/postgresql/pq_xindexes.cxx @@ -37,11 +37,13 @@ #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XParameters.hpp> #include <com/sun/star/sdbc/KeyRule.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xindexes.hxx" #include "pq_xindex.hxx" @@ -180,7 +182,9 @@ void Indexes::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx index 782861615707..1982d348851c 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeycolumns.cxx @@ -36,10 +36,12 @@ #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xcolumns.hxx" #include "pq_xkeycolumns.hxx" @@ -149,7 +151,9 @@ void KeyColumns::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx index 07ee93726a4d..09aa41ea0f15 100644 --- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx +++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx @@ -37,11 +37,13 @@ #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbc/XParameters.hpp> #include <com/sun/star/sdbc/KeyRule.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xkeys.hxx" #include "pq_xkey.hxx" @@ -198,7 +200,9 @@ void Keys::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx index 0eb86f12942c..907e777f273d 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx @@ -36,12 +36,14 @@ #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbcx/Privilege.hpp> #include <com/sun/star/sdbcx/KeyType.hpp> #include <com/sun/star/sdbc/KeyRule.hpp> #include <com/sun/star/sdbc/DataType.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xtables.hxx" #include "pq_xviews.hxx" @@ -142,7 +144,9 @@ void Tables::refresh() } catch ( const css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xusers.cxx b/connectivity/source/drivers/postgresql/pq_xusers.cxx index e7d6b6112b5a..cb30c0b50b4c 100644 --- a/connectivity/source/drivers/postgresql/pq_xusers.cxx +++ b/connectivity/source/drivers/postgresql/pq_xusers.cxx @@ -36,9 +36,11 @@ #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> #include <com/sun/star/sdbcx/Privilege.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xusers.hxx" #include "pq_xuser.hxx" @@ -109,7 +111,9 @@ void Users::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx index 7b1abf581468..8f1d58d07f8e 100644 --- a/connectivity/source/drivers/postgresql/pq_xviews.cxx +++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx @@ -36,8 +36,10 @@ #include <rtl/ustrbuf.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/SQLException.hpp> #include <com/sun/star/sdbc/XRow.hpp> +#include <cppuhelper/exc_hlp.hxx> #include "pq_xviews.hxx" #include "pq_xview.hxx" @@ -124,7 +126,9 @@ void Views::refresh() } catch ( css::sdbc::SQLException & e ) { - throw RuntimeException( e.Message , e.Context ); + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException( e.Message, + e.Context, anyEx ); } fire( RefreshedBroadcaster( *this ) ); } diff --git a/connectivity/source/sdbcx/VCollection.cxx b/connectivity/source/sdbcx/VCollection.cxx index 595b66576ed1..70f15dc4bd9d 100644 --- a/connectivity/source/sdbcx/VCollection.cxx +++ b/connectivity/source/sdbcx/VCollection.cxx @@ -27,6 +27,7 @@ #include <comphelper/enumhelper.hxx> #include <comphelper/types.hxx> #include <comphelper/property.hxx> +#include <cppuhelper/exc_hlp.hxx> #include <TConnection.hxx> #include <rtl/ustrbuf.hxx> #include <strings.hrc> @@ -533,6 +534,7 @@ ObjectType OCollection::getObject(sal_Int32 _nIndex) } catch(const SQLException& e) { + css::uno::Any anyEx = cppu::getCaughtException(); try { dropImpl(_nIndex,false); @@ -540,7 +542,7 @@ ObjectType OCollection::getObject(sal_Int32 _nIndex) catch(const Exception& ) { } - throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),makeAny(e)); + throw WrappedTargetException(e.Message,static_cast<XTypeProvider*>(this),anyEx); } m_pElements->setObject(_nIndex,xName); } |