Kaydet (Commit) ce2792ed authored tarafından Caolán McNamara's avatar Caolán McNamara

use C++11 exception rethrowing

for those cases where we are doing relatively simple catching and rethrowing
e.g. catch in one thread and throw in main thread.

Change-Id: I6192017c4ec99dd671a9582f7b004096b0fc4525
Reviewed-on: https://gerrit.libreoffice.org/58588
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst f9309a17
...@@ -61,27 +61,26 @@ public: ...@@ -61,27 +61,26 @@ public:
typedef GenericSolarThreadExecutor<FuncT, ResultT> ExecutorT; typedef GenericSolarThreadExecutor<FuncT, ResultT> ExecutorT;
::std::unique_ptr<ExecutorT> const pExecutor( new ExecutorT(func) ); ::std::unique_ptr<ExecutorT> const pExecutor( new ExecutorT(func) );
pExecutor->execute(); pExecutor->execute();
if (pExecutor->m_exc.hasValue()) if (pExecutor->m_exc)
::cppu::throwException( pExecutor->m_exc ); std::rethrow_exception(pExecutor->m_exc);
return *pExecutor->m_result; return *pExecutor->m_result;
} }
private: private:
explicit GenericSolarThreadExecutor( FuncT const& func ) explicit GenericSolarThreadExecutor( FuncT const& func )
: m_exc(), m_func(func), m_result() {} : m_func(func), m_result() {}
virtual void doIt() override virtual void doIt() override
{ {
try { try {
m_result.reset( m_func() ); m_result.reset( m_func() );
} }
catch (css::uno::Exception &) { catch (...) {
// only UNO exceptions can be dispatched: m_exc = std::current_exception();
m_exc = ::cppu::getCaughtException();
} }
} }
css::uno::Any m_exc; std::exception_ptr m_exc;
#ifdef _MSC_VER #ifdef _MSC_VER
FuncT m_func; // "const" and std::bind() results in Error C3848 expression would lose const-volatile qualifiers FuncT m_func; // "const" and std::bind() results in Error C3848 expression would lose const-volatile qualifiers
#else #else
...@@ -97,20 +96,19 @@ class GenericSolarThreadExecutor<FuncT, void> : public SolarThreadExecutor ...@@ -97,20 +96,19 @@ class GenericSolarThreadExecutor<FuncT, void> : public SolarThreadExecutor
{ {
private: private:
explicit GenericSolarThreadExecutor( FuncT const& func ) explicit GenericSolarThreadExecutor( FuncT const& func )
: m_exc(), m_func(func) {} : m_func(func) {}
virtual void doIt() override virtual void doIt() override
{ {
try { try {
m_func(); m_func();
} }
catch (css::uno::Exception &) { catch (...) {
// only UNO exceptions can be dispatched: m_exc = std::current_exception();
m_exc = ::cppu::getCaughtException();
} }
} }
css::uno::Any m_exc; std::exception_ptr m_exc;
FuncT const m_func; FuncT const m_func;
}; };
......
...@@ -47,7 +47,7 @@ class ZipOutputEntry ...@@ -47,7 +47,7 @@ class ZipOutputEntry
css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext; css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext;
css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext; css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext;
::css::uno::Any m_aParallelDeflateException; std::exception_ptr m_aParallelDeflateException;
CRC32 m_aCRC; CRC32 m_aCRC;
ZipEntry *m_pCurrentEntry; ZipEntry *m_pCurrentEntry;
...@@ -70,9 +70,9 @@ public: ...@@ -70,9 +70,9 @@ public:
const css::uno::Reference< css::uno::XComponentContext >& rxContext, const css::uno::Reference< css::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt); ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
void createBufferFile(); void createBufferFile();
void setParallelDeflateException(const ::css::uno::Any &rAny) { m_aParallelDeflateException = rAny; } void setParallelDeflateException(const std::exception_ptr& exception) { m_aParallelDeflateException = exception; }
css::uno::Reference< css::io::XInputStream > getData() const; css::uno::Reference< css::io::XInputStream > getData() const;
const css::uno::Any& getParallelDeflateException() const { return m_aParallelDeflateException; } const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; }
void closeBufferFile(); void closeBufferFile();
void deleteBufferFile(); void deleteBufferFile();
......
...@@ -40,7 +40,7 @@ class ZipOutputStream ...@@ -40,7 +40,7 @@ class ZipOutputStream
ByteChucker m_aChucker; ByteChucker m_aChucker;
ZipEntry *m_pCurrentEntry; ZipEntry *m_pCurrentEntry;
std::vector< ZipOutputEntry* > m_aEntries; std::vector< ZipOutputEntry* > m_aEntries;
::css::uno::Any m_aDeflateException; std::exception_ptr m_aDeflateException;
public: public:
ZipOutputStream( ZipOutputStream(
......
...@@ -29,9 +29,8 @@ private: ...@@ -29,9 +29,8 @@ private:
{ {
mxStream.produce(); mxStream.produce();
} }
catch (const css::uno::Exception &e) catch (...)
{ {
SAL_WARN("package", "Unexpected " << e );
mxStream.saveException(std::current_exception()); mxStream.saveException(std::current_exception());
} }
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
void produce(); void produce();
void setTerminateThread(); void setTerminateThread();
void saveException(std::exception_ptr exception) { maSavedException = exception; } void saveException(const std::exception_ptr& exception) { maSavedException = exception; }
// XInputStream // XInputStream
virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override; virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override;
......
...@@ -94,10 +94,10 @@ void ZipOutputStream::rawCloseEntry( bool bEncrypt ) ...@@ -94,10 +94,10 @@ void ZipOutputStream::rawCloseEntry( bool bEncrypt )
void ZipOutputStream::consumeScheduledThreadEntry(ZipOutputEntry* pCandidate) void ZipOutputStream::consumeScheduledThreadEntry(ZipOutputEntry* pCandidate)
{ {
//Any exceptions thrown in the threads were caught and stored for now //Any exceptions thrown in the threads were caught and stored for now
::css::uno::Any aCaughtException(pCandidate->getParallelDeflateException()); const std::exception_ptr& rCaughtException(pCandidate->getParallelDeflateException());
if (aCaughtException.hasValue()) if (rCaughtException)
{ {
m_aDeflateException = aCaughtException; // store it for later throwing m_aDeflateException = rCaughtException; // store it for later throwing
// the exception handler in DeflateThread should have cleaned temp file // the exception handler in DeflateThread should have cleaned temp file
delete pCandidate; delete pCandidate;
return; return;
...@@ -184,9 +184,9 @@ void ZipOutputStream::finish() ...@@ -184,9 +184,9 @@ void ZipOutputStream::finish()
m_xStream->flush(); m_xStream->flush();
m_aZipList.clear(); m_aZipList.clear();
if (m_aDeflateException.hasValue()) if (m_aDeflateException)
{ // throw once all threads are finished and m_aEntries can be released { // throw once all threads are finished and m_aEntries can be released
::cppu::throwException(m_aDeflateException); std::rethrow_exception(m_aDeflateException);
} }
} }
......
...@@ -473,9 +473,9 @@ private: ...@@ -473,9 +473,9 @@ private:
mpEntry->closeBufferFile(); mpEntry->closeBufferFile();
mpEntry->setFinished(); mpEntry->setFinished();
} }
catch (const uno::Exception&) catch (...)
{ {
mpEntry->setParallelDeflateException(::cppu::getCaughtException()); mpEntry->setParallelDeflateException(std::current_exception());
try try
{ {
if (mpEntry->m_xOutStream.is()) if (mpEntry->m_xOutStream.is())
......
...@@ -210,7 +210,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( ...@@ -210,7 +210,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
bSuccess = false; bSuccess = false;
while ( !bSuccess ) while ( !bSuccess )
{ {
Any aFirstCaughtException; std::exception_ptr aFirstCaughtException;
try try
{ {
invokeResult = xFunc->invoke( inArgs, outIndex, outArgs ); invokeResult = xFunc->invoke( inArgs, outIndex, outArgs );
...@@ -218,17 +218,17 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification( ...@@ -218,17 +218,17 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
} }
catch( const provider::ScriptFrameworkErrorException& se ) catch( const provider::ScriptFrameworkErrorException& se )
{ {
if ( !aFirstCaughtException.hasValue() ) if (!aFirstCaughtException)
aFirstCaughtException = ::cppu::getCaughtException(); aFirstCaughtException = std::current_exception();
if ( se.errorType != provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT ) if ( se.errorType != provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT )
// the only condition which allows us to retry is if there is no method with the // the only condition which allows us to retry is if there is no method with the
// given name/signature // given name/signature
::cppu::throwException( aFirstCaughtException ); std::rethrow_exception(aFirstCaughtException);
if ( inArgs.getLength() == 0 ) if ( inArgs.getLength() == 0 )
// no chance to retry if we can't strip more in-args // no chance to retry if we can't strip more in-args
::cppu::throwException( aFirstCaughtException ); std::rethrow_exception(aFirstCaughtException);
// strip one argument, then retry // strip one argument, then retry
inArgs.realloc( inArgs.getLength() - 1 ); inArgs.realloc( inArgs.getLength() - 1 );
......
...@@ -100,7 +100,7 @@ class GtkSalData : public GenericUnixSalData ...@@ -100,7 +100,7 @@ class GtkSalData : public GenericUnixSalData
GSource* m_pUserEvent; GSource* m_pUserEvent;
osl::Mutex m_aDispatchMutex; osl::Mutex m_aDispatchMutex;
osl::Condition m_aDispatchCondition; osl::Condition m_aDispatchCondition;
css::uno::Any m_aException; std::exception_ptr m_aException;
css::uno::Reference<css::accessibility::XAccessibleEventListener> m_xDocumentFocusListener; css::uno::Reference<css::accessibility::XAccessibleEventListener> m_xDocumentFocusListener;
DocumentFocusListener * m_pDocumentFocusListener; DocumentFocusListener * m_pDocumentFocusListener;
...@@ -127,7 +127,7 @@ public: ...@@ -127,7 +127,7 @@ public:
virtual bool ErrorTrapPop( bool bIgnoreError = true ) override; virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
inline GtkSalDisplay *GetGtkDisplay() const; inline GtkSalDisplay *GetGtkDisplay() const;
void setException(const css::uno::Any& rException) { m_aException = rException; } void setException(const std::exception_ptr& exception) { m_aException = exception; }
}; };
class GtkSalFrame; class GtkSalFrame;
......
...@@ -464,8 +464,8 @@ bool GtkSalData::Yield( bool bWait, bool bHandleAllCurrentEvents ) ...@@ -464,8 +464,8 @@ bool GtkSalData::Yield( bool bWait, bool bHandleAllCurrentEvents )
if( wasOneEvent ) if( wasOneEvent )
bWasEvent = true; bWasEvent = true;
} }
if (m_aException.hasValue()) if (m_aException)
::cppu::throwException(m_aException); std::rethrow_exception(m_aException);
} }
else if( bWait ) else if( bWait )
{ {
......
...@@ -4482,25 +4482,10 @@ bool GtkSalFrame::CallCallbackExc(SalEvent nEvent, const void* pEvent) const ...@@ -4482,25 +4482,10 @@ bool GtkSalFrame::CallCallbackExc(SalEvent nEvent, const void* pEvent) const
{ {
nRet = CallCallback(nEvent, pEvent); nRet = CallCallback(nEvent, pEvent);
} }
catch (const css::uno::Exception&)
{
auto e = cppu::getCaughtException();
GtkSalData *pSalData = static_cast<GtkSalData*>(GetSalData());
pSalData->setException(e);
}
catch (std::exception & e)
{
static_cast<GtkSalData *>(GetSalData())->setException(
css::uno::Any(
css::uno::RuntimeException(
"wrapped std::exception "
+ o3tl::runtimeToOUString(e.what()))));
}
catch (...) catch (...)
{ {
static_cast<GtkSalData *>(GetSalData())->setException( GtkSalData *pSalData = static_cast<GtkSalData*>(GetSalData());
css::uno::Any( pSalData->setException(std::current_exception());
css::uno::RuntimeException("wrapped unknown exception")));
} }
return nRet; return nRet;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment