connectivity/source/commontools/dbexception.cxx | 71 +++++++++++------------- include/connectivity/dbexception.hxx | 6 ++ 2 files changed, 40 insertions(+), 37 deletions(-)
New commits: commit fa89349b360945d726db0c5f85cd4ccb0822417f Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Fri Sep 24 10:41:27 2021 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Sep 24 13:43:57 2021 +0200 make SQLExceptionInfo utilities available for external use Change-Id: I6561fa433f6619d8de97983fa962f874cbf5b536 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122570 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/connectivity/source/commontools/dbexception.cxx b/connectivity/source/commontools/dbexception.cxx index 17f54b8bcaad..e6663f7d188b 100644 --- a/connectivity/source/commontools/dbexception.cxx +++ b/connectivity/source/commontools/dbexception.cxx @@ -187,49 +187,46 @@ void SQLExceptionInfo::prepend( const OUString& _rErrorMessage ) m_eType = TYPE::SQLException; } -namespace +// 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 createException(SQLExceptionInfo::TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode) + Any aAppend; + switch (eType) { - Any aAppend; - switch (eType) - { - case SQLExceptionInfo::TYPE::SQLException: - aAppend <<= SQLException(); - break; - case SQLExceptionInfo::TYPE::SQLWarning: - aAppend <<= SQLWarning(); - break; - case SQLExceptionInfo::TYPE::SQLContext: - aAppend <<= SQLContext(); - 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; + 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::createException: invalid exception type: this will crash!"); + break; } - // find the end of the exception chain - SQLException* getLastException(SQLException* pLastException) + 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 exception chain +SQLException* SQLExceptionInfo::getLastException(SQLException* pLastException) +{ + SQLException* pException = pLastException; + while (pException) { - SQLException* pException = pLastException; - while (pException) - { - pException = const_cast<SQLException*>(o3tl::tryAccess<SQLException>(pException->NextException)); - if (!pException) - break; - pLastException = pException; - } - return pLastException; + pException = const_cast<SQLException*>(o3tl::tryAccess<SQLException>(pException->NextException)); + if (!pException) + break; + pLastException = pException; } + return pLastException; } void SQLExceptionInfo::append( TYPE _eType, const OUString& _rErrorMessage, const OUString& _rSQLState, const sal_Int32 _nErrorCode ) diff --git a/include/connectivity/dbexception.hxx b/include/connectivity/dbexception.hxx index 4edd174e5635..8c9dfad33efe 100644 --- a/include/connectivity/dbexception.hxx +++ b/include/connectivity/dbexception.hxx @@ -131,6 +131,12 @@ public: m_eType = TYPE::Undefined; } + // create an exception + static css::uno::Any createException(TYPE eType, const OUString& rErrorMessage, const OUString& rSQLState, const sal_Int32 nErrorCode); + + // find the end of the exception chain + static css::sdbc::SQLException* getLastException(css::sdbc::SQLException* pLastException); + private: void implDetermineType(); };