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:
typedef GenericSolarThreadExecutor<FuncT, ResultT> ExecutorT;
::std::unique_ptr<ExecutorT> const pExecutor( new ExecutorT(func) );
pExecutor->execute();
if (pExecutor->m_exc.hasValue())
::cppu::throwException( pExecutor->m_exc );
if (pExecutor->m_exc)
std::rethrow_exception(pExecutor->m_exc);
return *pExecutor->m_result;
}
private:
explicit GenericSolarThreadExecutor( FuncT const& func )
: m_exc(), m_func(func), m_result() {}
: m_func(func), m_result() {}
virtual void doIt() override
{
try {
m_result.reset( m_func() );
}
catch (css::uno::Exception &) {
// only UNO exceptions can be dispatched:
m_exc = ::cppu::getCaughtException();
catch (...) {
m_exc = std::current_exception();
}
}
css::uno::Any m_exc;
std::exception_ptr m_exc;
#ifdef _MSC_VER
FuncT m_func; // "const" and std::bind() results in Error C3848 expression would lose const-volatile qualifiers
#else
......@@ -97,20 +96,19 @@ class GenericSolarThreadExecutor<FuncT, void> : public SolarThreadExecutor
{
private:
explicit GenericSolarThreadExecutor( FuncT const& func )
: m_exc(), m_func(func) {}
: m_func(func) {}
virtual void doIt() override
{
try {
m_func();
}
catch (css::uno::Exception &) {
// only UNO exceptions can be dispatched:
m_exc = ::cppu::getCaughtException();
catch (...) {
m_exc = std::current_exception();
}
}
css::uno::Any m_exc;
std::exception_ptr m_exc;
FuncT const m_func;
};
......
......@@ -47,7 +47,7 @@ class ZipOutputEntry
css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext;
css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext;
::css::uno::Any m_aParallelDeflateException;
std::exception_ptr m_aParallelDeflateException;
CRC32 m_aCRC;
ZipEntry *m_pCurrentEntry;
......@@ -70,9 +70,9 @@ public:
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
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;
const css::uno::Any& getParallelDeflateException() const { return m_aParallelDeflateException; }
const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; }
void closeBufferFile();
void deleteBufferFile();
......
......@@ -40,7 +40,7 @@ class ZipOutputStream
ByteChucker m_aChucker;
ZipEntry *m_pCurrentEntry;
std::vector< ZipOutputEntry* > m_aEntries;
::css::uno::Any m_aDeflateException;
std::exception_ptr m_aDeflateException;
public:
ZipOutputStream(
......
......@@ -29,9 +29,8 @@ private:
{
mxStream.produce();
}
catch (const css::uno::Exception &e)
catch (...)
{
SAL_WARN("package", "Unexpected " << e );
mxStream.saveException(std::current_exception());
}
......
......@@ -66,7 +66,7 @@ public:
void produce();
void setTerminateThread();
void saveException(std::exception_ptr exception) { maSavedException = exception; }
void saveException(const std::exception_ptr& exception) { maSavedException = exception; }
// XInputStream
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 )
void ZipOutputStream::consumeScheduledThreadEntry(ZipOutputEntry* pCandidate)
{
//Any exceptions thrown in the threads were caught and stored for now
::css::uno::Any aCaughtException(pCandidate->getParallelDeflateException());
if (aCaughtException.hasValue())
const std::exception_ptr& rCaughtException(pCandidate->getParallelDeflateException());
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
delete pCandidate;
return;
......@@ -184,9 +184,9 @@ void ZipOutputStream::finish()
m_xStream->flush();
m_aZipList.clear();
if (m_aDeflateException.hasValue())
if (m_aDeflateException)
{ // 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:
mpEntry->closeBufferFile();
mpEntry->setFinished();
}
catch (const uno::Exception&)
catch (...)
{
mpEntry->setParallelDeflateException(::cppu::getCaughtException());
mpEntry->setParallelDeflateException(std::current_exception());
try
{
if (mpEntry->m_xOutStream.is())
......
......@@ -210,7 +210,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
bSuccess = false;
while ( !bSuccess )
{
Any aFirstCaughtException;
std::exception_ptr aFirstCaughtException;
try
{
invokeResult = xFunc->invoke( inArgs, outIndex, outArgs );
......@@ -218,17 +218,17 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
}
catch( const provider::ScriptFrameworkErrorException& se )
{
if ( !aFirstCaughtException.hasValue() )
aFirstCaughtException = ::cppu::getCaughtException();
if (!aFirstCaughtException)
aFirstCaughtException = std::current_exception();
if ( se.errorType != provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT )
// the only condition which allows us to retry is if there is no method with the
// given name/signature
::cppu::throwException( aFirstCaughtException );
std::rethrow_exception(aFirstCaughtException);
if ( inArgs.getLength() == 0 )
// no chance to retry if we can't strip more in-args
::cppu::throwException( aFirstCaughtException );
std::rethrow_exception(aFirstCaughtException);
// strip one argument, then retry
inArgs.realloc( inArgs.getLength() - 1 );
......
......@@ -100,7 +100,7 @@ class GtkSalData : public GenericUnixSalData
GSource* m_pUserEvent;
osl::Mutex m_aDispatchMutex;
osl::Condition m_aDispatchCondition;
css::uno::Any m_aException;
std::exception_ptr m_aException;
css::uno::Reference<css::accessibility::XAccessibleEventListener> m_xDocumentFocusListener;
DocumentFocusListener * m_pDocumentFocusListener;
......@@ -127,7 +127,7 @@ public:
virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
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;
......
......@@ -464,8 +464,8 @@ bool GtkSalData::Yield( bool bWait, bool bHandleAllCurrentEvents )
if( wasOneEvent )
bWasEvent = true;
}
if (m_aException.hasValue())
::cppu::throwException(m_aException);
if (m_aException)
std::rethrow_exception(m_aException);
}
else if( bWait )
{
......
......@@ -4482,25 +4482,10 @@ bool GtkSalFrame::CallCallbackExc(SalEvent nEvent, const void* pEvent) const
{
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 (...)
{
static_cast<GtkSalData *>(GetSalData())->setException(
css::uno::Any(
css::uno::RuntimeException("wrapped unknown exception")));
GtkSalData *pSalData = static_cast<GtkSalData*>(GetSalData());
pSalData->setException(std::current_exception());
}
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