diff options
Diffstat (limited to 'connectivity/source/commontools/dbexception.cxx')
-rw-r--r-- | connectivity/source/commontools/dbexception.cxx | 99 |
1 files changed, 51 insertions, 48 deletions
diff --git a/connectivity/source/commontools/dbexception.cxx b/connectivity/source/commontools/dbexception.cxx index 2efc4a6976b3..113a96ea57f1 100644 --- a/connectivity/source/commontools/dbexception.cxx +++ b/connectivity/source/commontools/dbexception.cxx @@ -27,7 +27,7 @@ #include <com/sun/star/sdb/SQLErrorEvent.hpp> #include <strings.hrc> #include <resource/sharedresources.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> namespace dbtools { @@ -66,8 +66,7 @@ SQLExceptionInfo::SQLExceptionInfo(const css::sdb::SQLContext& _rError) SQLExceptionInfo::SQLExceptionInfo( const OUString& _rSimpleErrorMessage ) { - SQLException aError; - aError.Message = _rSimpleErrorMessage; + SQLException aError(_rSimpleErrorMessage, {}, {}, 0, {}); m_aContent <<= aError; implDetermineType(); } @@ -177,63 +176,67 @@ SQLExceptionInfo::operator const css::sdb::SQLContext*() const void SQLExceptionInfo::prepend( const OUString& _rErrorMessage ) { - SQLException aException; - aException.Message = _rErrorMessage; - aException.ErrorCode = 0; - aException.SQLState = "S1000"; - aException.NextException = m_aContent; + SQLException aException(_rErrorMessage, {}, u"S1000"_ustr, 0, m_aContent); m_aContent <<= aException; m_eType = TYPE::SQLException; } - -void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode ) +// create the to-be-appended exception +Any SQLExceptionInfo::createException(TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode) { - // create the to-be-appended exception Any aAppend; - switch ( _eType ) + switch (eType) { - case TYPE::SQLException: aAppend <<= SQLException(); break; - case TYPE::SQLWarning: aAppend <<= SQLWarning(); break; - case TYPE::SQLContext: aAppend <<= SQLContext(); break; - default: - TOOLS_WARN_EXCEPTION( "connectivity.commontools", "SQLExceptionInfo::append: invalid exception type: this will crash!" ); - break; + case TYPE::SQLException: + aAppend <<= SQLException(rErrorMessage, {}, rSQLState, nErrorCode, {}); + break; + case TYPE::SQLWarning: + aAppend <<= SQLWarning(rErrorMessage, {}, rSQLState, nErrorCode, {}); + break; + case TYPE::SQLContext: + aAppend <<= SQLContext(rErrorMessage, {}, rSQLState, nErrorCode, {}, {}); + break; + default: + TOOLS_WARN_EXCEPTION("connectivity.commontools", "SQLExceptionInfo::createException: invalid exception type: this will crash!"); + break; } - SQLException& pAppendException = const_cast<SQLException &>(*o3tl::forceAccess<SQLException>(aAppend)); - pAppendException.Message = _rErrorMessage; - pAppendException.SQLState = _rSQLState; - pAppendException.ErrorCode = _nErrorCode; + return aAppend; +} - // find the end of the current chain - Any* pChainIterator = &m_aContent; - SQLException* pLastException = nullptr; - const Type& aSQLExceptionType( cppu::UnoType<SQLException>::get() ); - while ( pChainIterator ) +// find the end of the exception chain +SQLException* SQLExceptionInfo::getLastException(SQLException* pLastException) +{ + SQLException* pException = pLastException; + while (pException) { - if ( !pChainIterator->hasValue() ) + pException = const_cast<SQLException*>(o3tl::tryAccess<SQLException>(pException->NextException)); + if (!pException) break; + pLastException = pException; + } + return pLastException; +} - if ( !isAssignableFrom( aSQLExceptionType, pChainIterator->getValueType() ) ) - break; +void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode ) +{ + // create the to-be-appended exception + Any aAppend = createException(_eType, _rErrorMessage, _rSQLState, _nErrorCode); - pLastException = const_cast< SQLException* >( o3tl::doAccess<SQLException>( *pChainIterator ) ); - pChainIterator = &pLastException->NextException; - } + // find the end of the current chain + SQLException* pLastException = getLastException(const_cast<SQLException*>(o3tl::tryAccess<SQLException>(m_aContent))); // append - if ( pLastException ) - pLastException->NextException = aAppend; + if (pLastException) + pLastException->NextException = std::move(aAppend); else { - m_aContent = aAppend; + m_aContent = std::move(aAppend); m_eType = _eType; } } - void SQLExceptionInfo::doThrow() { if ( m_aContent.getValueTypeClass() == TypeClass_EXCEPTION ) @@ -461,17 +464,17 @@ OUString getStandardSQLState( StandardSQLState _eState ) { switch ( _eState ) { - case StandardSQLState::INVALID_DESCRIPTOR_INDEX: return "07009"; - case StandardSQLState::INVALID_CURSOR_STATE: return "24000"; - case StandardSQLState::COLUMN_NOT_FOUND: return "42S22"; - case StandardSQLState::GENERAL_ERROR: return "HY000"; - case StandardSQLState::INVALID_SQL_DATA_TYPE: return "HY004"; - case StandardSQLState::FUNCTION_SEQUENCE_ERROR: return "HY010"; - case StandardSQLState::INVALID_CURSOR_POSITION: return "HY109"; - case StandardSQLState::FEATURE_NOT_IMPLEMENTED: return "HYC00"; - case StandardSQLState::FUNCTION_NOT_SUPPORTED: return "IM001"; - case StandardSQLState::CONNECTION_DOES_NOT_EXIST: return "08003"; - default: return "HY001"; // General Error + case StandardSQLState::INVALID_DESCRIPTOR_INDEX: return u"07009"_ustr; + case StandardSQLState::INVALID_CURSOR_STATE: return u"24000"_ustr; + case StandardSQLState::COLUMN_NOT_FOUND: return u"42S22"_ustr; + case StandardSQLState::GENERAL_ERROR: return u"HY000"_ustr; + case StandardSQLState::INVALID_SQL_DATA_TYPE: return u"HY004"_ustr; + case StandardSQLState::FUNCTION_SEQUENCE_ERROR: return u"HY010"_ustr; + case StandardSQLState::INVALID_CURSOR_POSITION: return u"HY109"_ustr; + case StandardSQLState::FEATURE_NOT_IMPLEMENTED: return u"HYC00"_ustr; + case StandardSQLState::FUNCTION_NOT_SUPPORTED: return u"IM001"_ustr; + case StandardSQLState::CONNECTION_DOES_NOT_EXIST: return u"08003"_ustr; + default: return u"HY001"_ustr; // General Error } } |