diff --git a/cpp/include/Glacier2/SessionHelper.h b/cpp/include/Glacier2/SessionHelper.h index c419f3f30b9..e3240260b71 100644 --- a/cpp/include/Glacier2/SessionHelper.h +++ b/cpp/include/Glacier2/SessionHelper.h @@ -122,7 +122,7 @@ class GLACIER2_API SessionCallback * @param session The corresponding session helper. * @param ex The exception that caused the failure. */ - virtual void connectFailed(const SessionHelperPtr& session, const Ice::Exception& ex) = 0; + virtual void connectFailed(const SessionHelperPtr& session, std::exception_ptr ex) = 0; }; using SessionCallbackPtr = std::shared_ptr; diff --git a/cpp/include/Ice/Incoming.h b/cpp/include/Ice/Incoming.h index 68436b2ca31..79d47431a0d 100644 --- a/cpp/include/Ice/Incoming.h +++ b/cpp/include/Ice/Incoming.h @@ -71,7 +71,7 @@ class ICE_API IncomingBase : private IceUtil::noncopyable void setMarshaledResult(const Ice::MarshaledResult&); void response(bool); - void exception(const std::exception&, bool); + void exception(std::exception_ptr, bool); void exception(const std::string&, bool); protected: @@ -84,7 +84,7 @@ class ICE_API IncomingBase : private IceUtil::noncopyable bool servantLocatorFinished(bool); - void handleException(const std::exception&, bool); + void handleException(std::exception_ptr, bool); void handleException(const std::string&, bool); Ice::Current _current; diff --git a/cpp/include/Ice/ObserverHelper.h b/cpp/include/Ice/ObserverHelper.h index 2e75f56b919..ef883c614c0 100644 --- a/cpp/include/Ice/ObserverHelper.h +++ b/cpp/include/Ice/ObserverHelper.h @@ -12,6 +12,8 @@ namespace IceInternal { +std::string getExceptionId(std::exception_ptr); + template class ObserverHelperT { public: diff --git a/cpp/include/Ice/OutgoingAsync.h b/cpp/include/Ice/OutgoingAsync.h index cf8d5347b07..1a31d77218a 100644 --- a/cpp/include/Ice/OutgoingAsync.h +++ b/cpp/include/Ice/OutgoingAsync.h @@ -34,11 +34,11 @@ class ICE_API OutgoingAsyncCompletionCallback protected: virtual bool handleSent(bool, bool) = 0; - virtual bool handleException(const Ice::Exception&) = 0; + virtual bool handleException(std::exception_ptr) = 0; virtual bool handleResponse(bool) = 0; virtual void handleInvokeSent(bool, OutgoingAsyncBase*) const = 0; - virtual void handleInvokeException(const Ice::Exception&, OutgoingAsyncBase*) const = 0; + virtual void handleInvokeException(std::exception_ptr, OutgoingAsyncBase*) const = 0; virtual void handleInvokeResponse(bool, OutgoingAsyncBase*) const = 0; }; @@ -53,7 +53,7 @@ class ICE_API OutgoingAsyncBase : public virtual OutgoingAsyncCompletionCallback public: virtual bool sent(); - virtual bool exception(const Ice::Exception&); + virtual bool exception(std::exception_ptr); virtual bool response(); void invokeSentAsync(); @@ -94,10 +94,10 @@ class ICE_API OutgoingAsyncBase : public virtual OutgoingAsyncCompletionCallback OutgoingAsyncBase(const InstancePtr&); bool sentImpl(bool); - bool exceptionImpl(const Ice::Exception&); + bool exceptionImpl(std::exception_ptr); bool responseImpl(bool, bool); - void cancel(const Ice::LocalException&); + void cancel(std::exception_ptr); void checkCanceled(); void warning(const std::exception&) const; @@ -121,8 +121,8 @@ class ICE_API OutgoingAsyncBase : public virtual OutgoingAsyncCompletionCallback std::mutex _m; using Lock = std::lock_guard; - std::unique_ptr _ex; - std::unique_ptr _cancellationException; + std::exception_ptr _ex; + std::exception_ptr _cancellationException; InvocationObserver _observer; ObserverHelperT _childObserver; @@ -150,12 +150,12 @@ class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase, virtual AsyncStatus invokeRemote(const Ice::ConnectionIPtr&, bool, bool) = 0; virtual AsyncStatus invokeCollocated(CollocatedRequestHandler*) = 0; - virtual bool exception(const Ice::Exception&); + virtual bool exception(std::exception_ptr); virtual void cancelable(const CancellationHandlerPtr&); - void retryException(const Ice::Exception&); + void retryException(); void retry(); - void abort(const Ice::Exception&); + void abort(std::exception_ptr); std::shared_ptr shared_from_this() { @@ -169,7 +169,7 @@ class ICE_API ProxyOutgoingAsyncBase : public OutgoingAsyncBase, void invokeImpl(bool); bool sentImpl(bool); - bool exceptionImpl(const Ice::Exception&); + bool exceptionImpl(std::exception_ptr); bool responseImpl(bool, bool); virtual void runTimerTask(); @@ -201,7 +201,7 @@ class ICE_API OutgoingAsync : public ProxyOutgoingAsyncBase virtual AsyncStatus invokeRemote(const Ice::ConnectionIPtr&, bool, bool); virtual AsyncStatus invokeCollocated(CollocatedRequestHandler*); - void abort(const Ice::Exception&); + void abort(std::exception_ptr); void invoke(const std::string&); void invoke(const std::string&, Ice::OperationMode, Ice::FormatType, const Ice::Context&, std::function); @@ -256,11 +256,11 @@ class ICE_API LambdaInvoke : public virtual OutgoingAsyncCompletionCallback protected: virtual bool handleSent(bool, bool) override; - virtual bool handleException(const Ice::Exception&) override; + virtual bool handleException(std::exception_ptr) override; virtual bool handleResponse(bool) override; virtual void handleInvokeSent(bool, OutgoingAsyncBase*) const override; - virtual void handleInvokeException(const Ice::Exception&, OutgoingAsyncBase*) const override; + virtual void handleInvokeException(std::exception_ptr, OutgoingAsyncBase*) const override; virtual void handleInvokeResponse(bool, OutgoingAsyncBase*) const override; std::function _exception; @@ -291,16 +291,9 @@ class PromiseInvoke : public virtual OutgoingAsyncCompletionCallback return false; } - virtual bool handleException(const Ice::Exception& ex) override + virtual bool handleException(std::exception_ptr ex) override { - try - { - ex.ice_throw(); - } - catch(const Ice::Exception&) - { - _promise.set_exception(std::current_exception()); - } + _promise.set_exception(ex); return false; } @@ -315,7 +308,7 @@ class PromiseInvoke : public virtual OutgoingAsyncCompletionCallback assert(false); } - virtual void handleInvokeException(const Ice::Exception&, OutgoingAsyncBase*) const override + virtual void handleInvokeException(std::exception_ptr, OutgoingAsyncBase*) const override { assert(false); } diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 25aa244009c..06cd7f526e7 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -125,9 +125,9 @@ class InvokeOutgoingAsyncT : public OutgoingAsync } OutgoingAsync::invoke(operation); } - catch(const Ice::Exception& ex) + catch (const std::exception&) { - abort(ex); + abort(std::current_exception()); } } @@ -1174,7 +1174,7 @@ class ICE_API ObjectPrx : public Proxy, public ::std::enable_shared_f const ::IceInternal::ReferencePtr& _getReference() const { return _reference; } - int _handleException(const ::Ice::Exception&, const ::IceInternal::RequestHandlerPtr&, ::Ice::OperationMode, + int _handleException(std::exception_ptr, const ::IceInternal::RequestHandlerPtr&, ::Ice::OperationMode, bool, int&); void _checkTwowayOnly(const ::std::string&) const; diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp index 7c2c17b950a..d94d2c699ca 100644 --- a/cpp/src/Glacier2Lib/SessionHelper.cpp +++ b/cpp/src/Glacier2Lib/SessionHelper.cpp @@ -476,25 +476,24 @@ class ConnectFailed : public Ice::DispatcherCall public: ConnectFailed(const Glacier2::SessionCallbackPtr& callback, const Glacier2::SessionHelperPtr& session, - const Ice::Exception& ex) : + std::exception_ptr ex) : _callback(callback), _session(session) { - _ex = ex.ice_clone(); + _ex = ex; } virtual void run() { - const Ice::Exception* ex(_ex.get()); - _callback->connectFailed(_session, *ex); + _callback->connectFailed(_session, _ex); } private: const Glacier2::SessionCallbackPtr _callback; const Glacier2::SessionHelperPtr _session; - unique_ptr _ex; + std::exception_ptr _ex; }; class CreatedCommunicator : public Ice::DispatcherCall @@ -544,13 +543,13 @@ class ConnectThread : public IceUtil::Thread communicator = Ice::initialize(_session->_initData); _session->_communicator = communicator; } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { { lock_guard lock(_session->_mutex); _session->_destroy = true; } - _session->dispatchCallback(new ConnectFailed(_callback, _session, ex), nullptr); + _session->dispatchCallback(new ConnectFailed(_callback, _session, current_exception()), nullptr); return; } @@ -564,9 +563,9 @@ class ConnectThread : public IceUtil::Thread finder = Ice::uncheckedCast(communicator->stringToProxy(_finder)); communicator->setDefaultRouter(finder->getRouter()); } - catch(const Ice::CommunicatorDestroyedException& ex) + catch(const Ice::CommunicatorDestroyedException&) { - _session->dispatchCallback(new ConnectFailed(_callback, _session, ex), 0); + _session->dispatchCallback(new ConnectFailed(_callback, _session, current_exception()), 0); return; } catch(const Ice::Exception&) @@ -586,7 +585,7 @@ class ConnectThread : public IceUtil::Thread Glacier2::SessionPrxPtr session = _factory->connect(routerPrx); _session->connected(routerPrx, session); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { try { @@ -596,7 +595,7 @@ class ConnectThread : public IceUtil::Thread { } - _session->dispatchCallback(new ConnectFailed(_callback, _session, ex), 0); + _session->dispatchCallback(new ConnectFailed(_callback, _session, current_exception()), 0); } _session = 0; } diff --git a/cpp/src/Ice/BatchRequestQueue.cpp b/cpp/src/Ice/BatchRequestQueue.cpp index 9fec6090b86..a07a3f9a854 100644 --- a/cpp/src/Ice/BatchRequestQueue.cpp +++ b/cpp/src/Ice/BatchRequestQueue.cpp @@ -90,7 +90,7 @@ BatchRequestQueue::prepareBatchRequest(OutputStream* os) unique_lock lock(_mutex); if(_exception) { - _exception->ice_throw(); + rethrow_exception(_exception); } _conditionVariable.wait(lock, [this] { return !_batchStreamInUse; }); @@ -203,10 +203,10 @@ BatchRequestQueue::swap(OutputStream* os, bool& compress) } void -BatchRequestQueue::destroy(const Ice::LocalException& ex) +BatchRequestQueue::destroy(std::exception_ptr ex) { lock_guard lock(_mutex); - _exception = ex.ice_clone(); + _exception = ex; } bool diff --git a/cpp/src/Ice/BatchRequestQueue.h b/cpp/src/Ice/BatchRequestQueue.h index d27abbd8591..564fae80305 100644 --- a/cpp/src/Ice/BatchRequestQueue.h +++ b/cpp/src/Ice/BatchRequestQueue.h @@ -30,7 +30,7 @@ class BatchRequestQueue : public IceUtil::Shared int swap(Ice::OutputStream*, bool&); - void destroy(const Ice::LocalException&); + void destroy(std::exception_ptr); bool isEmpty(); void enqueueBatchRequest(const Ice::ObjectPrxPtr&); @@ -44,7 +44,7 @@ class BatchRequestQueue : public IceUtil::Shared bool _batchCompress; int _batchRequestNum; size_t _batchMarker; - std::unique_ptr _exception; + std::exception_ptr _exception; size_t _maxSize; std::mutex _mutex; diff --git a/cpp/src/Ice/CollocatedRequestHandler.cpp b/cpp/src/Ice/CollocatedRequestHandler.cpp index 1e2c921c7a5..00aa7d58fa0 100644 --- a/cpp/src/Ice/CollocatedRequestHandler.cpp +++ b/cpp/src/Ice/CollocatedRequestHandler.cpp @@ -90,7 +90,7 @@ CollocatedRequestHandler::sendAsyncRequest(const ProxyOutgoingAsyncBasePtr& outA } void -CollocatedRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, const LocalException& ex) +CollocatedRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, exception_ptr ex) { lock_guard lock(_mutex); @@ -257,7 +257,7 @@ CollocatedRequestHandler::sendNoResponse() } bool -CollocatedRequestHandler::systemException(Int requestId, const SystemException& ex, bool amd) +CollocatedRequestHandler::systemException(Int requestId, exception_ptr ex, bool amd) { handleException(requestId, ex, amd); _adapter->decDirectCount(); @@ -265,7 +265,7 @@ CollocatedRequestHandler::systemException(Int requestId, const SystemException& } void -CollocatedRequestHandler::invokeException(Int requestId, const LocalException& ex, int /*invokeNum*/, bool amd) +CollocatedRequestHandler::invokeException(Int requestId, exception_ptr ex, int /*invokeNum*/, bool amd) { handleException(requestId, ex, amd); _adapter->decDirectCount(); @@ -346,9 +346,9 @@ CollocatedRequestHandler::invokeAll(OutputStream* os, Int requestId, Int batchRe { _adapter->incDirectCount(); } - catch(const ObjectAdapterDeactivatedException& ex) + catch(const ObjectAdapterDeactivatedException&) { - handleException(requestId, ex, false); + handleException(requestId, current_exception(), false); break; } @@ -357,16 +357,16 @@ CollocatedRequestHandler::invokeAll(OutputStream* os, Int requestId, Int batchRe --invokeNum; } } - catch(const LocalException& ex) + catch(const LocalException&) { - invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception + invokeException(requestId, current_exception(), invokeNum, false); // Fatal invocation exception } _adapter->decDirectCount(); } void -CollocatedRequestHandler::handleException(int requestId, const Exception& ex, bool amd) +CollocatedRequestHandler::handleException(int requestId, std::exception_ptr ex, bool amd) { if(requestId == 0) { diff --git a/cpp/src/Ice/CollocatedRequestHandler.h b/cpp/src/Ice/CollocatedRequestHandler.h index 0e89496e771..2b5b4b2e760 100644 --- a/cpp/src/Ice/CollocatedRequestHandler.h +++ b/cpp/src/Ice/CollocatedRequestHandler.h @@ -39,12 +39,12 @@ class CollocatedRequestHandler : public RequestHandler, public ResponseHandler virtual AsyncStatus sendAsyncRequest(const ProxyOutgoingAsyncBasePtr&); - virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, const Ice::LocalException&); + virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, std::exception_ptr); virtual void sendResponse(Ice::Int, Ice::OutputStream*, Ice::Byte, bool); virtual void sendNoResponse(); - virtual bool systemException(Ice::Int, const Ice::SystemException&, bool); - virtual void invokeException(Ice::Int, const Ice::LocalException&, int, bool); + virtual bool systemException(Ice::Int, std::exception_ptr, bool); + virtual void invokeException(Ice::Int, std::exception_ptr, int, bool); const ReferencePtr& getReference() const { return _reference; } // Inlined for performances. @@ -64,7 +64,7 @@ class CollocatedRequestHandler : public RequestHandler, public ResponseHandler private: - void handleException(Ice::Int, const Ice::Exception&, bool); + void handleException(Ice::Int, std::exception_ptr, bool); const std::shared_ptr _adapter; const bool _dispatcher; diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 4bf7087bdef..0c7cb722c3e 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -61,9 +61,9 @@ CommunicatorFlushBatchAsync::flushConnection(const ConnectionIPtr& con, Ice::Com } virtual bool - exception(const Exception& ex) + exception(std::exception_ptr ex) { - _childObserver.failed(ex.ice_id()); + _childObserver.failed(getExceptionId(ex)); _childObserver.detach(); _outAsync->check(false); return false; @@ -80,7 +80,7 @@ CommunicatorFlushBatchAsync::flushConnection(const ConnectionIPtr& con, Ice::Com return false; } - virtual bool handleException(const Ice::Exception&) + virtual bool handleException(std::exception_ptr) { return false; } @@ -95,7 +95,7 @@ CommunicatorFlushBatchAsync::flushConnection(const ConnectionIPtr& con, Ice::Com assert(false); } - virtual void handleInvokeException(const Ice::Exception&, OutgoingAsyncBase*) const + virtual void handleInvokeException(std::exception_ptr, OutgoingAsyncBase*) const { assert(false); } diff --git a/cpp/src/Ice/ConnectRequestHandler.cpp b/cpp/src/Ice/ConnectRequestHandler.cpp index 35290cb0ff7..7048b996393 100644 --- a/cpp/src/Ice/ConnectRequestHandler.cpp +++ b/cpp/src/Ice/ConnectRequestHandler.cpp @@ -62,7 +62,7 @@ ConnectRequestHandler::sendAsyncRequest(const ProxyOutgoingAsyncBasePtr& out) } void -ConnectRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, const Ice::LocalException& ex) +ConnectRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, exception_ptr ex) { { unique_lock lock(_mutex); @@ -105,7 +105,7 @@ ConnectRequestHandler::getConnection() } else if(_exception) { - _exception->ice_throw(); + rethrow_exception(_exception); } return nullptr; } @@ -116,7 +116,7 @@ ConnectRequestHandler::waitForConnection() unique_lock lock(_mutex); if(_exception) { - throw RetryException(*_exception); + throw RetryException(_exception); } // // Wait for the connection establishment to complete or fail. @@ -125,8 +125,7 @@ ConnectRequestHandler::waitForConnection() if(_exception) { - _exception->ice_throw(); - return 0; // Keep the compiler happy. + rethrow_exception(_exception); } else { @@ -161,13 +160,13 @@ ConnectRequestHandler::setConnection(const Ice::ConnectionIPtr& connection, bool } void -ConnectRequestHandler::setException(const Ice::LocalException& ex) +ConnectRequestHandler::setException(exception_ptr ex) { { lock_guard lock(_mutex); assert(!_flushing && !_initialized && !_exception); _flushing = true; // Ensures request handler is removed before processing new requests. - _exception = ex.ice_clone(); + _exception = ex; } // @@ -184,13 +183,14 @@ ConnectRequestHandler::setException(const Ice::LocalException& ex) // Ignore } - for(deque::const_iterator p = _requests.begin(); p != _requests.end(); ++p) + for (deque::const_iterator p = _requests.begin(); p != _requests.end(); ++p) { - if((*p)->exception(ex)) + if ((*p)->exception(ex)) { (*p)->invokeExceptionAsync(); } } + _requests.clear(); { @@ -238,8 +238,7 @@ ConnectRequestHandler::initialized(unique_lock& lock) // return true; } - _exception->ice_throw(); - return false; // Keep the compiler happy. + rethrow_exception(_exception); } else { @@ -263,7 +262,7 @@ ConnectRequestHandler::flushRequests() _flushing = true; } - std::unique_ptr exception; + exception_ptr exception; while(!_requests.empty()) // _requests is immutable when _flushing = true { ProxyOutgoingAsyncBasePtr& req = _requests.front(); @@ -276,18 +275,18 @@ ConnectRequestHandler::flushRequests() } catch(const RetryException& ex) { - exception = ex.get()->ice_clone(); + exception = ex.get(); // Remove the request handler before retrying. _reference->getInstance()->requestHandlerFactory()->removeRequestHandler(_reference, shared_from_this()); - req->retryException(*exception); + req->retryException(); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - exception = ex.ice_clone(); + exception = current_exception(); - if(req->exception(ex)) + if(req->exception(exception)) { req->invokeExceptionAsync(); } diff --git a/cpp/src/Ice/ConnectRequestHandler.h b/cpp/src/Ice/ConnectRequestHandler.h index 011c53f14f6..7515678d9dc 100644 --- a/cpp/src/Ice/ConnectRequestHandler.h +++ b/cpp/src/Ice/ConnectRequestHandler.h @@ -34,13 +34,13 @@ class ConnectRequestHandler final : virtual AsyncStatus sendAsyncRequest(const ProxyOutgoingAsyncBasePtr&); - virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, const Ice::LocalException&); + virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, std::exception_ptr); virtual Ice::ConnectionIPtr getConnection(); virtual Ice::ConnectionIPtr waitForConnection(); virtual void setConnection(const Ice::ConnectionIPtr&, bool); - virtual void setException(const Ice::LocalException&); + virtual void setException(std::exception_ptr); virtual void addedProxy(); @@ -54,7 +54,7 @@ class ConnectRequestHandler final : Ice::ConnectionIPtr _connection; bool _compress; - std::unique_ptr _exception; + std::exception_ptr _exception; bool _initialized; bool _flushing; diff --git a/cpp/src/Ice/ConnectionFactory.cpp b/cpp/src/Ice/ConnectionFactory.cpp index a5cdd1436c9..a16871a1601 100644 --- a/cpp/src/Ice/ConnectionFactory.cpp +++ b/cpp/src/Ice/ConnectionFactory.cpp @@ -231,9 +231,9 @@ IceInternal::OutgoingConnectionFactory::create(const vector& endpt return; } } - catch(const Ice::LocalException& ex) + catch (const std::exception&) { - callback->setException(ex); + callback->setException(current_exception()); return; } @@ -689,7 +689,7 @@ IceInternal::OutgoingConnectionFactory::finishGetConnection(const vector& connectors, - const Ice::LocalException& ex, + std::exception_ptr ex, const ConnectCallbackPtr& cb) { ConnectCallbackSet failedCallbacks; @@ -795,7 +795,7 @@ IceInternal::OutgoingConnectionFactory::removeFromPending(const ConnectCallbackP } void -IceInternal::OutgoingConnectionFactory::handleException(const LocalException& ex, bool hasMore) +IceInternal::OutgoingConnectionFactory::handleException(exception_ptr ex, bool hasMore) { TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->network >= 2) @@ -803,11 +803,16 @@ IceInternal::OutgoingConnectionFactory::handleException(const LocalException& ex Trace out(_instance->initializationData().logger, traceLevels->networkCat); out << "couldn't resolve endpoint host"; - if(dynamic_cast(&ex)) + + try { - out << "\n"; + rethrow_exception(ex); } - else + catch (const CommunicatorDestroyedException& e) + { + out << "\n" << e; + } + catch (const std::exception& e) { if(hasMore) { @@ -817,13 +822,13 @@ IceInternal::OutgoingConnectionFactory::handleException(const LocalException& ex { out << " and no more endpoints to try\n"; } + out << e; } - out << ex; } } void -IceInternal::OutgoingConnectionFactory::handleConnectionException(const LocalException& ex, bool hasMore) +IceInternal::OutgoingConnectionFactory::handleConnectionException(exception_ptr ex, bool hasMore) { TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->network >= 2) @@ -831,11 +836,16 @@ IceInternal::OutgoingConnectionFactory::handleConnectionException(const LocalExc Trace out(_instance->initializationData().logger, traceLevels->networkCat); out << "connection to endpoint failed"; - if(dynamic_cast(&ex)) + + try { - out << "\n"; + rethrow_exception(ex); } - else + catch (const CommunicatorDestroyedException& e) + { + out << "\n" << e; + } + catch (const std::exception& e) { if(hasMore) { @@ -845,8 +855,8 @@ IceInternal::OutgoingConnectionFactory::handleConnectionException(const LocalExc { out << " and no more endpoints to try\n"; } + out << e; } - out << ex; } } @@ -883,7 +893,7 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::connectionStartComplete void IceInternal::OutgoingConnectionFactory::ConnectCallback::connectionStartFailed(const ConnectionIPtr& /*connection*/, - const LocalException& ex) + exception_ptr ex) { assert(_iter != _connectors.end()); if(connectionStartFailedImpl(ex)) @@ -921,7 +931,7 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::connectors(const vector } void -IceInternal::OutgoingConnectionFactory::ConnectCallback::exception(const Ice::LocalException& ex) +IceInternal::OutgoingConnectionFactory::ConnectCallback::exception(exception_ptr ex) { _factory->handleException(ex, _hasMore || _endpointsIter != _endpoints.end() - 1); if(++_endpointsIter != _endpoints.end()) @@ -956,9 +966,9 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::getConnectors() // _factory->incPendingConnectCount(); } - catch(const Ice::LocalException& ex) + catch (const std::exception&) { - _callback->setException(ex); + _callback->setException(current_exception()); return; } @@ -974,9 +984,9 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::nextEndpoint() (*_endpointsIter)->connectors_async(_selType, shared_from_this()); } - catch(const Ice::LocalException& ex) + catch (const std::exception&) { - exception(ex); + exception(current_exception()); } } @@ -1005,9 +1015,9 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::getConnection() _callback->setConnection(connection, compress); _factory->decPendingConnectCount(); // Must be called last. } - catch(const Ice::LocalException& ex) + catch (const std::exception&) { - _callback->setException(ex); + _callback->setException(current_exception()); _factory->decPendingConnectCount(); // Must be called last. } } @@ -1049,7 +1059,7 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::nextConnector() << _iter->connector->toString() << "\n" << ex; } - if(connectionStartFailedImpl(ex)) + if(connectionStartFailedImpl(current_exception())) { continue; // More connectors to try, continue. } @@ -1071,7 +1081,7 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::setConnection(const Ice } void -IceInternal::OutgoingConnectionFactory::ConnectCallback::setException(const Ice::LocalException& ex) +IceInternal::OutgoingConnectionFactory::ConnectCallback::setException(exception_ptr ex) { // // Callback from the factory: connection establishment failed. @@ -1114,16 +1124,30 @@ IceInternal::OutgoingConnectionFactory::ConnectCallback::operator<(const Connect } bool -IceInternal::OutgoingConnectionFactory::ConnectCallback::connectionStartFailedImpl(const Ice::LocalException& ex) +IceInternal::OutgoingConnectionFactory::ConnectCallback::connectionStartFailedImpl(std::exception_ptr ex) { + bool communicatorDestroyed = false; + try + { + rethrow_exception(ex); + } + catch (const CommunicatorDestroyedException&) + { + communicatorDestroyed = true; + } + catch (...) + { + } + if(_observer) { - _observer->failed(ex.ice_id()); + _observer->failed(getExceptionId(ex)); _observer->detach(); } _factory->handleConnectionException(ex, _hasMore || _iter != _connectors.end() - 1); - if(dynamic_cast(&ex)) // No need to continue. + + if(communicatorDestroyed) // No need to continue. { _factory->finishGetConnection(_connectors, ex, shared_from_this()); } @@ -1325,9 +1349,9 @@ IceInternal::IncomingConnectionFactory::startAsync(SocketOperation) { _acceptor->startAccept(); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - _acceptorException = ex.ice_clone(); + _acceptorException = current_exception(); _acceptor->getNativeInfo()->completed(SocketOperationRead); } return true; @@ -1341,13 +1365,13 @@ IceInternal::IncomingConnectionFactory::finishAsync(SocketOperation) { if(_acceptorException) { - _acceptorException->ice_throw(); + rethrow_exception(_acceptorException); } _acceptor->finishAccept(); } catch(const LocalException& ex) { - _acceptorException.reset(nullptr); + _acceptorException = nullptr; Error out(_instance->initializationData().logger); out << "couldn't accept connection:\n" << ex << '\n' << _acceptor->toString(); @@ -1579,7 +1603,7 @@ IceInternal::IncomingConnectionFactory::connectionStartCompleted(const Ice::Conn void IceInternal::IncomingConnectionFactory::connectionStartFailed(const Ice::ConnectionIPtr& /*connection*/, - const Ice::LocalException&) + exception_ptr) { lock_guard lock(_mutex); if(_state >= StateClosed) diff --git a/cpp/src/Ice/ConnectionFactory.h b/cpp/src/Ice/ConnectionFactory.h index d0a65a12c20..f01cd1eec07 100644 --- a/cpp/src/Ice/ConnectionFactory.h +++ b/cpp/src/Ice/ConnectionFactory.h @@ -30,7 +30,6 @@ namespace Ice { -class LocalException; class ObjectAdapterI; } @@ -49,7 +48,7 @@ class OutgoingConnectionFactory final : public std::enable_shared_from_this; @@ -92,10 +91,10 @@ class OutgoingConnectionFactory final : public std::enable_shared_from_this&); - virtual void exception(const Ice::LocalException&); + virtual void exception(std::exception_ptr); void getConnectors(); void nextEndpoint(); @@ -104,7 +103,7 @@ class OutgoingConnectionFactory final : public std::enable_shared_from_this&); @@ -114,7 +113,7 @@ class OutgoingConnectionFactory final : public std::enable_shared_from_this&, const ConnectCallbackPtr&, bool&); void finishGetConnection(const std::vector&, const ConnectorInfo&, const Ice::ConnectionIPtr&, const ConnectCallbackPtr&); - void finishGetConnection(const std::vector&, const Ice::LocalException&, const ConnectCallbackPtr&); + void finishGetConnection(const std::vector&, std::exception_ptr, const ConnectCallbackPtr&); bool addToPending(const ConnectCallbackPtr&, const std::vector&); void removeFromPending(const ConnectCallbackPtr&, const std::vector&); @@ -145,8 +144,8 @@ class OutgoingConnectionFactory final : public std::enable_shared_from_this&, bool&); Ice::ConnectionIPtr createConnection(const TransceiverPtr&, const ConnectorInfo&); - void handleException(const Ice::LocalException&, bool); - void handleConnectionException(const Ice::LocalException&, bool); + void handleException(std::exception_ptr, bool); + void handleConnectionException(std::exception_ptr, bool); Ice::CommunicatorPtr _communicator; const InstancePtr _instance; @@ -205,7 +204,7 @@ class IncomingConnectionFactory final : public EventHandler, public Ice::Connect virtual NativeInfoPtr getNativeInfo(); virtual void connectionStartCompleted(const Ice::ConnectionIPtr&); - virtual void connectionStartFailed(const Ice::ConnectionIPtr&, const Ice::LocalException&); + virtual void connectionStartFailed(const Ice::ConnectionIPtr&, std::exception_ptr); void initialize(); ~IncomingConnectionFactory(); @@ -248,7 +247,7 @@ class IncomingConnectionFactory final : public EventHandler, public Ice::Connect State _state; #if defined(ICE_USE_IOCP) - std::unique_ptr _acceptorException; + std::exception_ptr _acceptorException; #endif mutable std::mutex _mutex; mutable std::condition_variable _conditionVariable; diff --git a/cpp/src/Ice/ConnectionI.cpp b/cpp/src/Ice/ConnectionI.cpp index 1894b9825a4..42796993a89 100644 --- a/cpp/src/Ice/ConnectionI.cpp +++ b/cpp/src/Ice/ConnectionI.cpp @@ -207,14 +207,21 @@ ConnectionFlushBatchAsync::invoke(const string& operation, Ice::CompressBatch co } catch(const RetryException& ex) { - if(exception(*ex.get())) + try { - invokeExceptionAsync(); + rethrow_exception(ex.get()); + } + catch (const std::exception&) + { + if (exception(current_exception())) + { + invokeExceptionAsync(); + } } } - catch(const Exception& ex) + catch(const Exception&) { - if(exception(ex)) + if(exception(current_exception())) { invokeExceptionAsync(); } @@ -356,7 +363,7 @@ Ice::ConnectionI::OutgoingMessage::sent() } void -Ice::ConnectionI::OutgoingMessage::completed(const Ice::LocalException& ex) +Ice::ConnectionI::OutgoingMessage::completed(std::exception_ptr ex) { if(outAsync) { @@ -382,7 +389,7 @@ Ice::ConnectionI::start(const StartCallbackPtr& callback) if(_state >= StateClosed) // The connection might already be closed if the communicator was destroyed. { assert(_exception); - _exception->ice_throw(); + rethrow_exception(_exception); } if(!initialize() || !validate()) @@ -401,7 +408,7 @@ Ice::ConnectionI::start(const StartCallbackPtr& callback) if(_state >= StateClosing) { assert(_exception); - _exception->ice_throw(); + rethrow_exception(_exception); } } @@ -410,12 +417,12 @@ Ice::ConnectionI::start(const StartCallbackPtr& callback) // setState(StateHolding); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - exception(ex); + exception(current_exception()); if(callback) { - callback->connectionStartFailed(shared_from_this(), ex); + callback->connectionStartFailed(shared_from_this(), current_exception()); return; } else @@ -467,13 +474,13 @@ Ice::ConnectionI::destroy(DestructionReason reason) { case ObjectAdapterDeactivated: { - setState(StateClosing, ObjectAdapterDeactivatedException(__FILE__, __LINE__)); + setState(StateClosing, make_exception_ptr(ObjectAdapterDeactivatedException(__FILE__, __LINE__))); break; } case CommunicatorDestroyed: { - setState(StateClosing, CommunicatorDestroyedException(__FILE__, __LINE__)); + setState(StateClosing, make_exception_ptr(CommunicatorDestroyedException(__FILE__, __LINE__))); break; } } @@ -486,11 +493,11 @@ Ice::ConnectionI::close(ConnectionClose mode) noexcept if(mode == ConnectionClose::Forcefully) { - setState(StateClosed, ConnectionManuallyClosedException(__FILE__, __LINE__, false)); + setState(StateClosed, make_exception_ptr(ConnectionManuallyClosedException(__FILE__, __LINE__, false))); } else if(mode == ConnectionClose::Gracefully) { - setState(StateClosing, ConnectionManuallyClosedException(__FILE__, __LINE__, true)); + setState(StateClosing, make_exception_ptr(ConnectionManuallyClosedException(__FILE__, __LINE__, true))); } else { @@ -501,7 +508,7 @@ Ice::ConnectionI::close(ConnectionClose mode) noexcept // _conditionVariable.wait(lock, [this]{ return _asyncRequests.empty(); }); - setState(StateClosing, ConnectionManuallyClosedException(__FILE__, __LINE__, true)); + setState(StateClosing, make_exception_ptr(ConnectionManuallyClosedException(__FILE__, __LINE__, true))); } } @@ -549,7 +556,7 @@ Ice::ConnectionI::throwException() const if(_exception) { assert(_state >= StateClosing); - _exception->ice_throw(); + rethrow_exception(_exception); } } @@ -651,7 +658,7 @@ Ice::ConnectionI::monitor(const IceUtil::Time& now, const ACMConfig& acm) // Close the connection if we didn't receive a heartbeat in // the last period. // - setState(StateClosed, ConnectionTimeoutException(__FILE__, __LINE__)); + setState(StateClosed, make_exception_ptr(ConnectionTimeoutException(__FILE__, __LINE__))); } else if(acm.close != ACMClose::CloseOnInvocation && _dispatchCount == 0 && _batchRequestQueue->isEmpty() && _asyncRequests.empty()) @@ -659,7 +666,7 @@ Ice::ConnectionI::monitor(const IceUtil::Time& now, const ACMConfig& acm) // // The connection is idle, close it. // - setState(StateClosing, ConnectionTimeoutException(__FILE__, __LINE__)); + setState(StateClosing, make_exception_ptr(ConnectionTimeoutException(__FILE__, __LINE__))); } } } @@ -677,7 +684,7 @@ Ice::ConnectionI::sendAsyncRequest(const OutgoingAsyncBasePtr& out, bool compres // if(_exception) { - throw RetryException(*_exception); + throw RetryException(_exception); } assert(_state > StateNotValidated); assert(_state < StateClosing); @@ -734,11 +741,11 @@ Ice::ConnectionI::sendAsyncRequest(const OutgoingAsyncBasePtr& out, bool compres OutgoingMessage message(out, os, compress, requestId); status = sendMessage(message); } - catch(const LocalException& ex) + catch(const LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); assert(_exception); - _exception->ice_throw(); + rethrow_exception(_exception); } if(response) @@ -841,14 +848,14 @@ class HeartbeatAsync : public OutgoingAsyncBase } catch(const RetryException& ex) { - if(exception(*ex.get())) + if(exception(ex.get())) { invokeExceptionAsync(); } } - catch(const Exception& ex) + catch(const Exception&) { - if(exception(ex)) + if(exception(current_exception())) { invokeExceptionAsync(); } @@ -1005,7 +1012,7 @@ Ice::ConnectionI::getACM() noexcept } void -Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, const LocalException& ex) +Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, exception_ptr ex) { // // NOTE: This isn't called from a thread pool thread. @@ -1035,11 +1042,15 @@ Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, con } } - if(dynamic_cast(&ex)) + try + { + rethrow_exception(ex); + } + catch (const Ice::ConnectionTimeoutException&) { setState(StateClosed, ex); } - else + catch (const std::exception&) { // // If the request is being sent, don't remove it from the send streams, @@ -1069,11 +1080,15 @@ Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, con { if(_asyncRequestsHint->second == outAsync) { - if(dynamic_cast(&ex)) + try + { + rethrow_exception(ex); + } + catch (const Ice::ConnectionTimeoutException&) { setState(StateClosed, ex); } - else + catch (const std::exception&) { _asyncRequests.erase(_asyncRequestsHint); _asyncRequestsHint = _asyncRequests.end(); @@ -1090,11 +1105,15 @@ Ice::ConnectionI::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, con { if(p->second.get() == outAsync.get()) { - if(dynamic_cast(&ex)) + try + { + rethrow_exception(ex); + } + catch (const Ice::ConnectionTimeoutException&) { setState(StateClosed, ex); } - else + catch (const std::exception&) { assert(p != _asyncRequestsHint); _asyncRequests.erase(p); @@ -1129,7 +1148,7 @@ Ice::ConnectionI::sendResponse(Int, OutputStream* os, Byte compressFlag, bool /* if(_state >= StateClosed) { assert(_exception); - _exception->ice_throw(); + rethrow_exception(_exception); } OutgoingMessage message(os, compressFlag > 0); @@ -1142,9 +1161,9 @@ Ice::ConnectionI::sendResponse(Int, OutputStream* os, Byte compressFlag, bool /* return; } - catch(const LocalException& ex) + catch(const LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } } @@ -1168,7 +1187,7 @@ Ice::ConnectionI::sendNoResponse() if(_state >= StateClosed) { assert(_exception); - _exception->ice_throw(); + rethrow_exception(_exception); } if(_state == StateClosing && _dispatchCount == 0) @@ -1176,20 +1195,20 @@ Ice::ConnectionI::sendNoResponse() initiateShutdown(); } } - catch(const LocalException& ex) + catch(const LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } } bool -Ice::ConnectionI::systemException(Int, const SystemException&, bool /*amd*/) +Ice::ConnectionI::systemException(Int, std::exception_ptr, bool /*amd*/) { return false; // System exceptions aren't marshalled. } void -Ice::ConnectionI::invokeException(Ice::Int, const LocalException& ex, int invokeNum, bool /*amd*/) +Ice::ConnectionI::invokeException(Ice::Int, exception_ptr ex, int invokeNum, bool /*amd*/) { // // Fatal exception while invoking a request. Since sendResponse/sendNoResponse isn't @@ -1325,9 +1344,9 @@ Ice::ConnectionI::startAsync(SocketOperation operation) _transceiver->startRead(_readStream); } } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); return false; } return true; @@ -1383,9 +1402,9 @@ Ice::ConnectionI::finishAsync(SocketOperation operation) } } } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } return _state < StateClosed; } @@ -1636,9 +1655,9 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) _readHeader = true; return; } - catch(const SocketException& ex) + catch(const SocketException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); return; } catch(const LocalException& ex) @@ -1656,7 +1675,7 @@ Ice::ConnectionI::message(ThreadPoolCurrent& current) } else { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } return; } @@ -1793,9 +1812,9 @@ ConnectionI::dispatch(const StartCallbackPtr& startCB, const vectorinitializationData().logger, _instance->traceLevels()->networkCat); - out << "failed to " << verb << " " << _endpoint->protocol() << " connection\n" << toString() - << "\n" << *_exception; + try + { + rethrow_exception(_exception); + } + catch (const std::exception& ex) + { + out << "failed to " << verb << " " << _endpoint->protocol() << " connection\n" << toString() + << "\n" << ex; + } } } else @@ -1865,13 +1891,28 @@ Ice::ConnectionI::finish(bool close) Trace out(_instance->initializationData().logger, _instance->traceLevels()->networkCat); out << "closed " << _endpoint->protocol() << " connection\n" << toString(); - if(!(dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()))) + try + { + rethrow_exception(_exception); + } + catch (const CloseConnectionException&) + { + } + catch (const ConnectionManuallyClosedException&) + { + } + catch (const ConnectionTimeoutException&) + { + } + catch (const CommunicatorDestroyedException&) + { + } + catch (const ObjectAdapterDeactivatedException&) + { + } + catch (const std::exception& ex) { - out << "\n" << *_exception; + out << "\n" << ex; } } } @@ -1893,7 +1934,7 @@ Ice::ConnectionI::finish(bool close) { assert(_exception); - _startCallback->connectionStartFailed(shared_from_this(), *_exception); + _startCallback->connectionStartFailed(shared_from_this(), _exception); _startCallback = 0; } @@ -1935,7 +1976,7 @@ Ice::ConnectionI::finish(bool close) for(deque::iterator o = _sendStreams.begin(); o != _sendStreams.end(); ++o) { - o->completed(*_exception); + o->completed(_exception); if(o->requestId) // Make sure finished isn't called twice. { _asyncRequests.erase(o->requestId); @@ -1947,7 +1988,7 @@ Ice::ConnectionI::finish(bool close) for(map::const_iterator q = _asyncRequests.begin(); q != _asyncRequests.end(); ++q) { - if(q->second->exception(*_exception)) + if(q->second->exception(_exception)) { q->second->invokeException(); } @@ -2004,15 +2045,15 @@ Ice::ConnectionI::timedOut() std::lock_guard lock(_mutex); if(_state <= StateNotValidated) { - setState(StateClosed, ConnectTimeoutException(__FILE__, __LINE__)); + setState(StateClosed, make_exception_ptr(ConnectTimeoutException(__FILE__, __LINE__))); } else if(_state < StateClosing) { - setState(StateClosed, TimeoutException(__FILE__, __LINE__)); + setState(StateClosed, make_exception_ptr(TimeoutException(__FILE__, __LINE__))); } else if(_state < StateClosed) { - setState(StateClosed, CloseTimeoutException(__FILE__, __LINE__)); + setState(StateClosed, make_exception_ptr(CloseTimeoutException(__FILE__, __LINE__))); } } @@ -2034,7 +2075,7 @@ Ice::ConnectionI::getInfo() const std::lock_guard lock(_mutex); if(_state >= StateClosed) { - _exception->ice_throw(); + rethrow_exception(_exception); } return initConnectionInfo(); } @@ -2045,14 +2086,14 @@ Ice::ConnectionI::setBufferSize(Ice::Int rcvSize, Ice::Int sndSize) std::lock_guard lock(_mutex); if(_state >= StateClosed) { - _exception->ice_throw(); + rethrow_exception(_exception); } _transceiver->setBufferSize(rcvSize, sndSize); _info = 0; // Invalidate the cached connection info } void -Ice::ConnectionI::exception(const LocalException& ex) +Ice::ConnectionI::exception(std::exception_ptr ex) { std::lock_guard lock(_mutex); setState(StateClosed, ex); @@ -2157,7 +2198,7 @@ Ice::ConnectionI::~ConnectionI() } void -Ice::ConnectionI::setState(State state, const LocalException& ex) +Ice::ConnectionI::setState(State state, exception_ptr ex) { // // If setState() is called with an exception, then only closed and @@ -2176,7 +2217,7 @@ Ice::ConnectionI::setState(State state, const LocalException& ex) // If we are in closed state, an exception must be set. // assert(_state != StateClosed); - _exception = ex.ice_clone(); + _exception = ex; // // We don't warn if we are not validated. // @@ -2185,15 +2226,37 @@ Ice::ConnectionI::setState(State state, const LocalException& ex) // // Don't warn about certain expected exceptions. // - if(!(dynamic_cast(&ex) || - dynamic_cast(&ex) || - dynamic_cast(&ex) || - dynamic_cast(&ex) || - dynamic_cast(&ex) || - (dynamic_cast(&ex) && _state >= StateClosing))) + try + { + rethrow_exception(ex); + } + catch (const CloseConnectionException&) + { + } + catch (const ConnectionManuallyClosedException&) + { + } + catch (const ConnectionTimeoutException&) + { + } + catch (const CommunicatorDestroyedException&) + { + } + catch (const ObjectAdapterDeactivatedException&) + { + } + catch (const ConnectionLostException& e) + { + if (_state < StateClosing) + { + Warning out(_logger); + out << "connection exception:\n" << e << '\n' << _desc; + } + } + catch (const std::exception& e) { Warning out(_logger); - out << "connection exception:\n" << ex << '\n' << _desc; + out << "connection exception:\n" << e << '\n' << _desc; } } } @@ -2302,7 +2365,7 @@ Ice::ConnectionI::setState(State state) return; } - _batchRequestQueue->destroy(*_exception); + _batchRequestQueue->destroy(_exception); // // Don't need to close now for connections so only close the transceiver @@ -2364,14 +2427,39 @@ Ice::ConnectionI::setState(State state) } if(_observer && state == StateClosed && _exception) { - if(!(dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - dynamic_cast(_exception.get()) || - (dynamic_cast(_exception.get()) && _state >= StateClosing))) + try + { + rethrow_exception(_exception); + } + catch (const CloseConnectionException&) { - _observer->failed(_exception->ice_id()); + } + catch (const ConnectionManuallyClosedException&) + { + } + catch (const ConnectionTimeoutException&) + { + } + catch (const CommunicatorDestroyedException&) + { + } + catch (const ObjectAdapterDeactivatedException&) + { + } + catch (const ConnectionLostException& ex) + { + if (_state < StateClosing) + { + _observer->failed(ex.ice_id()); + } + } + catch (const Ice::Exception& ex) + { + _observer->failed(ex.ice_id()); + } + catch (const std::exception& ex) + { + _observer->failed(ex.what()); } } } @@ -2385,9 +2473,9 @@ Ice::ConnectionI::setState(State state) { initiateShutdown(); } - catch(const LocalException& ex) + catch(const LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } } } @@ -2427,7 +2515,7 @@ Ice::ConnectionI::initiateShutdown() // // Notify the transceiver of the graceful connection closure. // - SocketOperation op = _transceiver->closing(true, *_exception); + SocketOperation op = _transceiver->closing(true, _exception); if(op) { scheduleTimeout(op); @@ -2460,9 +2548,9 @@ Ice::ConnectionI::sendHeartbeatNow() OutgoingMessage message(&os, false); sendMessage(message); } - catch(const LocalException& ex) + catch(const LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); assert(_exception); } } @@ -2758,16 +2846,16 @@ Ice::ConnectionI::sendNextMessage(vector& callbacks) if(_state == StateClosing && _shutdownInitiated) { setState(StateClosingPending); - SocketOperation op = _transceiver->closing(true, *_exception); + SocketOperation op = _transceiver->closing(true, _exception); if(op) { return op; } } } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } return SocketOperationNone; } @@ -3106,12 +3194,12 @@ Ice::ConnectionI::parseMessage(InputStream& stream, Int& invokeNum, Int& request } else { - setState(StateClosingPending, CloseConnectionException(__FILE__, __LINE__)); + setState(StateClosingPending, make_exception_ptr(CloseConnectionException(__FILE__, __LINE__))); // // Notify the transceiver of the graceful connection closure. // - SocketOperation op = _transceiver->closing(false, *_exception); + SocketOperation op = _transceiver->closing(false, _exception); if(op) { return op; @@ -3266,7 +3354,7 @@ Ice::ConnectionI::parseMessage(InputStream& stream, Int& invokeNum, Int& request } else { - setState(StateClosed, ex); + setState(StateClosed, current_exception()); } } @@ -3304,9 +3392,9 @@ Ice::ConnectionI::invokeAll(InputStream& stream, Int invokeNum, Int requestId, B stream.clear(); } - catch(const LocalException& ex) + catch(const LocalException&) { - invokeException(requestId, ex, invokeNum, false); // Fatal invocation exception + invokeException(requestId, current_exception(), invokeNum, false); // Fatal invocation exception } } diff --git a/cpp/src/Ice/ConnectionI.h b/cpp/src/Ice/ConnectionI.h index 5ff01d07cf7..b5841ed6919 100644 --- a/cpp/src/Ice/ConnectionI.h +++ b/cpp/src/Ice/ConnectionI.h @@ -106,7 +106,7 @@ class ConnectionI : public Connection, void adopt(Ice::OutputStream*); void canceled(bool); bool sent(); - void completed(const Ice::LocalException&); + void completed(std::exception_ptr); Ice::OutputStream* stream; IceInternal::OutgoingAsyncBasePtr outAsync; @@ -125,7 +125,7 @@ class ConnectionI : public Connection, public: virtual void connectionStartCompleted(const ConnectionIPtr&) = 0; - virtual void connectionStartFailed(const ConnectionIPtr&, const Ice::LocalException&) = 0; + virtual void connectionStartFailed(const ConnectionIPtr&, std::exception_ptr) = 0; }; using StartCallbackPtr = ::std::shared_ptr; @@ -175,12 +175,12 @@ class ConnectionI : public Connection, const std::optional&); virtual ACM getACM() noexcept; - virtual void asyncRequestCanceled(const IceInternal::OutgoingAsyncBasePtr&, const LocalException&); + virtual void asyncRequestCanceled(const IceInternal::OutgoingAsyncBasePtr&, std::exception_ptr); virtual void sendResponse(Int, Ice::OutputStream*, Byte, bool); virtual void sendNoResponse(); - virtual bool systemException(Int, const SystemException&, bool); - virtual void invokeException(Ice::Int, const LocalException&, int, bool); + virtual bool systemException(Int, std::exception_ptr, bool); + virtual void invokeException(Ice::Int, std::exception_ptr, int, bool); IceInternal::EndpointIPtr endpoint() const; IceInternal::ConnectorPtr connector() const; @@ -213,7 +213,7 @@ class ConnectionI : public Connection, virtual void setBufferSize(Ice::Int rcvSize, Ice::Int sndSize); // From Connection - void exception(const LocalException&); + void exception(std::exception_ptr); void dispatch(const StartCallbackPtr&, const std::vector&, Byte, Int, Int, const IceInternal::ServantManagerPtr&, const ObjectAdapterPtr&, @@ -252,7 +252,7 @@ class ConnectionI : public Connection, friend class IceInternal::IncomingConnectionFactory; friend class IceInternal::OutgoingConnectionFactory; - void setState(State, const LocalException&); + void setState(State, std::exception_ptr); void setState(State); void initiateShutdown(); @@ -325,7 +325,7 @@ class ConnectionI : public Connection, std::map _asyncRequests; std::map::iterator _asyncRequestsHint; - std::unique_ptr _exception; + std::exception_ptr _exception; const size_t _messageSizeMax; IceInternal::BatchRequestQueuePtr _batchRequestQueue; diff --git a/cpp/src/Ice/ConnectionRequestHandler.cpp b/cpp/src/Ice/ConnectionRequestHandler.cpp index bcab3152074..7f74b8a7a58 100644 --- a/cpp/src/Ice/ConnectionRequestHandler.cpp +++ b/cpp/src/Ice/ConnectionRequestHandler.cpp @@ -55,7 +55,7 @@ ConnectionRequestHandler::sendAsyncRequest(const ProxyOutgoingAsyncBasePtr& out) } void -ConnectionRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, const Ice::LocalException& ex) +ConnectionRequestHandler::asyncRequestCanceled(const OutgoingAsyncBasePtr& outAsync, exception_ptr ex) { _connection->asyncRequestCanceled(outAsync, ex); } diff --git a/cpp/src/Ice/ConnectionRequestHandler.h b/cpp/src/Ice/ConnectionRequestHandler.h index bf71d410ae3..a83c541f436 100644 --- a/cpp/src/Ice/ConnectionRequestHandler.h +++ b/cpp/src/Ice/ConnectionRequestHandler.h @@ -24,7 +24,7 @@ class ConnectionRequestHandler final : virtual AsyncStatus sendAsyncRequest(const ProxyOutgoingAsyncBasePtr&); - virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, const Ice::LocalException&); + virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, std::exception_ptr); virtual Ice::ConnectionIPtr getConnection(); virtual Ice::ConnectionIPtr waitForConnection(); diff --git a/cpp/src/Ice/EndpointI.h b/cpp/src/Ice/EndpointI.h index 23f147d1736..131f3591b88 100644 --- a/cpp/src/Ice/EndpointI.h +++ b/cpp/src/Ice/EndpointI.h @@ -30,7 +30,7 @@ class ICE_API EndpointI_connectors virtual ~EndpointI_connectors(); virtual void connectors(const std::vector&) = 0; - virtual void exception(const Ice::LocalException&) = 0; + virtual void exception(std::exception_ptr) = 0; }; class ICE_API EndpointI : public Ice::Endpoint diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp index 7d8a50b0558..16409b781a0 100644 --- a/cpp/src/Ice/IPEndpointI.cpp +++ b/cpp/src/Ice/IPEndpointI.cpp @@ -526,9 +526,9 @@ IceInternal::EndpointHostResolver::resolve(const string& host, int port, Ice::En return; } } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - callback->exception(ex); + callback->exception(current_exception()); return; } } @@ -633,19 +633,20 @@ IceInternal::EndpointHostResolver::run() r.observer->failed(ex.ice_id()); r.observer->detach(); } - r.callback->exception(ex); + r.callback->exception(current_exception()); } } for(deque::const_iterator p = _queue.begin(); p != _queue.end(); ++p) { Ice::CommunicatorDestroyedException ex(__FILE__, __LINE__); + auto eptr = make_exception_ptr(ex); if(p->observer) { p->observer->failed(ex.ice_id()); p->observer->detach(); } - p->callback->exception(ex); + p->callback->exception(eptr); } _queue.clear(); diff --git a/cpp/src/Ice/Incoming.cpp b/cpp/src/Ice/Incoming.cpp index f58ddd175c0..83e3746eba0 100644 --- a/cpp/src/Ice/Incoming.cpp +++ b/cpp/src/Ice/Incoming.cpp @@ -18,7 +18,6 @@ #include #include #include -#include using namespace std; using namespace Ice; @@ -164,9 +163,9 @@ IceInternal::IncomingBase::response(bool amd) _responseHandler->sendNoResponse(); } } - catch(const LocalException& ex) + catch(const LocalException&) { - _responseHandler->invokeException(_current.requestId, ex, 1, amd); // Fatal invocation exception + _responseHandler->invokeException(_current.requestId, current_exception(), 1, amd); // Fatal invocation exception } _observer.detach(); @@ -174,7 +173,7 @@ IceInternal::IncomingBase::response(bool amd) } void -IceInternal::IncomingBase::exception(const std::exception& exc, bool amd) +IceInternal::IncomingBase::exception(std::exception_ptr exc, bool amd) { try { @@ -184,9 +183,9 @@ IceInternal::IncomingBase::exception(const std::exception& exc, bool amd) } handleException(exc, amd); } - catch(const LocalException& ex) + catch(const LocalException&) { - _responseHandler->invokeException(_current.requestId, ex, 1, amd); // Fatal invocation exception + _responseHandler->invokeException(_current.requestId, current_exception(), 1, amd); // Fatal invocation exception } } @@ -201,9 +200,9 @@ IceInternal::IncomingBase::exception(const string& msg, bool amd) } handleException(msg, amd); } - catch(const LocalException& ex) + catch(const LocalException&) { - _responseHandler->invokeException(_current.requestId, ex, 1, amd); // Fatal invocation exception + _responseHandler->invokeException(_current.requestId, current_exception(), 1, amd); // Fatal invocation exception } } @@ -275,9 +274,9 @@ IceInternal::IncomingBase::servantLocatorFinished(bool amd) _locator->finished(_current, _servant, _cookie); return true; } - catch(const std::exception& ex) + catch(const std::exception&) { - handleException(ex, amd); + handleException(current_exception(), amd); } catch(...) { @@ -287,7 +286,7 @@ IceInternal::IncomingBase::servantLocatorFinished(bool amd) } void -IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) +IceInternal::IncomingBase::handleException(std::exception_ptr exc, bool amd) { assert(_responseHandler); @@ -296,57 +295,50 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _os.clear(); _os.b.clear(); - if(const SystemException* ex = dynamic_cast(&exc)) + try { - if(_responseHandler->systemException(_current.requestId, *ex, amd)) - { - return; - } + rethrow_exception(exc); } - - if(dynamic_cast(&exc)) + catch (RequestFailedException& rfe) { - RequestFailedException* rfe = - const_cast(dynamic_cast(&exc)); - - if(rfe->id.name.empty()) + if(rfe.id.name.empty()) { - rfe->id = _current.id; + rfe.id = _current.id; } - if(rfe->facet.empty() && !_current.facet.empty()) + if(rfe.facet.empty() && !_current.facet.empty()) { - rfe->facet = _current.facet; + rfe.facet = _current.facet; } - if(rfe->operation.empty() && !_current.operation.empty()) + if(rfe.operation.empty() && !_current.operation.empty()) { - rfe->operation = _current.operation; + rfe.operation = _current.operation; } if(_os.instance()->initializationData().properties->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) { - warning(*rfe); + warning(rfe); } if(_observer) { - _observer.failed(rfe->ice_id()); + _observer.failed(rfe.ice_id()); } if(_response) { _os.writeBlob(replyHdr, sizeof(replyHdr)); _os.write(_current.requestId); - if(dynamic_cast(rfe)) + if(dynamic_cast(&rfe)) { _os.write(replyObjectNotExist); } - else if(dynamic_cast(rfe)) + else if(dynamic_cast(&rfe)) { _os.write(replyFacetNotExist); } - else if(dynamic_cast(rfe)) + else if(dynamic_cast(&rfe)) { _os.write(replyOperationNotExist); } @@ -355,21 +347,21 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) assert(false); } - _os.write(rfe->id); + _os.write(rfe.id); // // For compatibility with the old FacetPath. // - if(rfe->facet.empty()) + if(rfe.facet.empty()) { _os.write(static_cast(0), static_cast(0)); } else { - _os.write(&rfe->facet, &rfe->facet + 1); + _os.write(&rfe.facet, &rfe.facet + 1); } - _os.write(rfe->operation, false); + _os.write(rfe.operation, false); _observer.reply(static_cast(_os.b.size() - headerSize - 4)); _responseHandler->sendResponse(_current.requestId, &_os, _compress, amd); @@ -379,7 +371,7 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _responseHandler->sendNoResponse(); } } - else if(const UserException* uex = dynamic_cast(&exc)) + catch (const UserException& uex) { _observer.userException(); @@ -392,7 +384,7 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _os.write(_current.requestId); _os.write(replyUserException); _os.startEncapsulation(_current.encoding, _format); - _os.write(*uex); + _os.write(uex); _os.endEncapsulation(); _observer.reply(static_cast(_os.b.size() - headerSize - 4)); _responseHandler->sendResponse(_current.requestId, &_os, _compress, amd); @@ -402,56 +394,65 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _responseHandler->sendNoResponse(); } } - else if(const Exception* ex = dynamic_cast(&exc)) + catch (const Exception& ex) { + if (dynamic_cast(&ex)) + { + if(_responseHandler->systemException(_current.requestId, exc, amd)) + { + return; + } + // else, keep going + } + if(_os.instance()->initializationData().properties->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - warning(*ex); + warning(ex); } if(_observer) { - _observer.failed(ex->ice_id()); + _observer.failed(ex.ice_id()); } if(_response) { _os.writeBlob(replyHdr, sizeof(replyHdr)); _os.write(_current.requestId); - if(const UnknownLocalException* ule = dynamic_cast(&exc)) + if(const UnknownLocalException* ule = dynamic_cast(&ex)) { _os.write(replyUnknownLocalException); _os.write(ule->unknown, false); } - else if(const UnknownUserException* uue = dynamic_cast(&exc)) + else if(const UnknownUserException* uue = dynamic_cast(&ex)) { _os.write(replyUnknownUserException); _os.write(uue->unknown, false); } - else if(const UnknownException* ue = dynamic_cast(&exc)) + else if(const UnknownException* ue = dynamic_cast(&ex)) { _os.write(replyUnknownException); _os.write(ue->unknown, false); } - else if(const LocalException* le = dynamic_cast(&exc)) + else if(const LocalException* le = dynamic_cast(&ex)) { _os.write(replyUnknownLocalException); ostringstream str; str << *le; if(IceUtilInternal::printStackTraces) { - str << '\n' << ex->ice_stackTrace(); + str << '\n' << ex.ice_stackTrace(); } _os.write(str.str(), false); } - else if(const UserException* use = dynamic_cast(&exc)) + else if(const UserException* use = dynamic_cast(&ex)) { _os.write(replyUnknownUserException); ostringstream str; str << *use; if(IceUtilInternal::printStackTraces) { - str << '\n' << ex->ice_stackTrace(); + str << '\n' << ex.ice_stackTrace(); } _os.write(str.str(), false); } @@ -459,10 +460,10 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) { _os.write(replyUnknownException); ostringstream str; - str << *ex; + str << ex; if(IceUtilInternal::printStackTraces) { - str << '\n' << ex->ice_stackTrace(); + str << '\n' << ex.ice_stackTrace(); } _os.write(str.str(), false); } @@ -475,16 +476,16 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _responseHandler->sendNoResponse(); } } - else + catch (const std::exception& ex) { if(_os.instance()->initializationData().properties->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) { - warning(string("std::exception: ") + exc.what()); + warning(string("std::exception: ") + ex.what()); } if(_observer) { - _observer.failed(typeid(exc).name()); + _observer.failed(ex.what()); } if(_response) @@ -493,7 +494,7 @@ IceInternal::IncomingBase::handleException(const std::exception& exc, bool amd) _os.write(_current.requestId); _os.write(replyUnknownException); ostringstream str; - str << "std::exception: " << exc.what(); + str << "std::exception: " << ex.what(); _os.write(str.str(), false); _observer.reply(static_cast(_os.b.size() - headerSize - 4)); @@ -671,10 +672,10 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager, InputStre { _servant = _locator->locate(_current, _cookie); } - catch(const std::exception& ex) + catch(const std::exception&) { skipReadParams(); // Required for batch requests. - handleException(ex, false); + handleException(current_exception(), false); return; } catch(...) @@ -700,10 +701,10 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager, InputStre throw ObjectNotExistException(__FILE__, __LINE__, _current.id, _current.facet, _current.operation); } } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { skipReadParams(); // Required for batch requests - handleException(ex, false); + handleException(current_exception(), false); return; } } @@ -748,7 +749,7 @@ IceInternal::Incoming::invoke(const ServantManagerPtr& servantManager, InputStre return; } } - exception(ex, false); + exception(current_exception(), false); } catch(...) { diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 1c1d1c208e8..62e4ce39fe9 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -90,9 +90,9 @@ IceInternal::IncomingAsync::completed(exception_ptr ex) { rethrow_exception(ex); } - catch(const std::exception& exc) + catch(const std::exception&) { - IncomingBase::exception(exc, true); // User thread + IncomingBase::exception(current_exception(), true); // User thread } catch(...) { diff --git a/cpp/src/Ice/LocatorInfo.cpp b/cpp/src/Ice/LocatorInfo.cpp index 8437299f910..792f69271f4 100644 --- a/cpp/src/Ice/LocatorInfo.cpp +++ b/cpp/src/Ice/LocatorInfo.cpp @@ -44,19 +44,12 @@ class ObjectRequest final : public LocatorInfo::Request, public std::enable_shar }, [request](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Exception& ex) - { - request->exception(ex); - } + request->exception(e); }); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } }; @@ -82,19 +75,12 @@ class AdapterRequest final : public LocatorInfo::Request, public std::enable_sha }, [request](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Exception& ex) - { - request->exception(ex); - } + request->exception(e); }); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } }; @@ -361,17 +347,17 @@ IceInternal::LocatorInfo::RequestCallback::response(const LocatorInfoPtr& locato } void -IceInternal::LocatorInfo::RequestCallback::exception(const LocatorInfoPtr& locatorInfo, const Ice::Exception& exc) +IceInternal::LocatorInfo::RequestCallback::exception(const LocatorInfoPtr& locatorInfo, std::exception_ptr exc) { try { locatorInfo->getEndpointsException(_reference, exc); // This throws. } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { if(_callback) { - _callback->setException(ex); + _callback->setException(current_exception()); } } } @@ -416,7 +402,7 @@ IceInternal::LocatorInfo::Request::addCallback(const ReferencePtr& ref, else { assert(_exception); - callback->exception(_locatorInfo, *_exception); + callback->exception(_locatorInfo, _exception); } } @@ -441,12 +427,25 @@ IceInternal::LocatorInfo::Request::response(const Ice::ObjectPrxPtr& proxy) } void -IceInternal::LocatorInfo::Request::exception(const Ice::Exception& ex) +IceInternal::LocatorInfo::Request::exception(std::exception_ptr ex) { + bool isUserException = false; + try + { + rethrow_exception(ex); + } + catch (const Ice::UserException&) + { + isUserException = true; + } + catch (...) + { + } + { lock_guard lock(_mutex); - _locatorInfo->finishRequest(_reference, _wellKnownRefs, 0, dynamic_cast(&ex)); - _exception = ex.ice_clone(); + _locatorInfo->finishRequest(_reference, _wellKnownRefs, 0, isUserException); + _exception = ex; } for(vector::const_iterator p = _callbacks.begin(); p != _callbacks.end(); ++p) { @@ -621,13 +620,13 @@ IceInternal::LocatorInfo::clearCache(const ReferencePtr& ref) } void -IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, const Ice::Exception& exc) +IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, std::exception_ptr exc) { assert(ref->isIndirect()); try { - exc.ice_throw(); + rethrow_exception(exc); } catch(const AdapterNotFoundException&) { diff --git a/cpp/src/Ice/LocatorInfo.h b/cpp/src/Ice/LocatorInfo.h index 7c8df36ee87..cfeb971fd0f 100644 --- a/cpp/src/Ice/LocatorInfo.h +++ b/cpp/src/Ice/LocatorInfo.h @@ -83,7 +83,7 @@ class LocatorInfo final : public std::enable_shared_from_this public: virtual void setEndpoints(const std::vector&, bool) = 0; - virtual void setException(const Ice::LocalException&) = 0; + virtual void setException(std::exception_ptr) = 0; }; using GetEndpointsCallbackPtr = std::shared_ptr; @@ -94,7 +94,7 @@ class LocatorInfo final : public std::enable_shared_from_this RequestCallback(const ReferencePtr&, int, const GetEndpointsCallbackPtr&); void response(const LocatorInfoPtr&, const Ice::ObjectPrxPtr&); - void exception(const LocatorInfoPtr&, const Ice::Exception&); + void exception(const LocatorInfoPtr&, std::exception_ptr); private: @@ -111,7 +111,7 @@ class LocatorInfo final : public std::enable_shared_from_this void addCallback(const ReferencePtr&, const ReferencePtr&, int, const GetEndpointsCallbackPtr&); void response(const Ice::ObjectPrxPtr&); - void exception(const Ice::Exception&); + void exception(std::exception_ptr); protected: @@ -130,7 +130,7 @@ class LocatorInfo final : public std::enable_shared_from_this bool _sent; bool _response; Ice::ObjectPrxPtr _proxy; - std::unique_ptr _exception; + std::exception_ptr _exception; }; using RequestPtr = std::shared_ptr; @@ -160,7 +160,7 @@ class LocatorInfo final : public std::enable_shared_from_this private: - void getEndpointsException(const ReferencePtr&, const Ice::Exception&); + void getEndpointsException(const ReferencePtr&, std::exception_ptr); void getEndpointsTrace(const ReferencePtr&, const std::vector&, bool); void trace(const std::string&, const ReferencePtr&, const std::vector&); void trace(const std::string&, const ReferencePtr&, const ReferencePtr&); diff --git a/cpp/src/Ice/LoggerAdminI.cpp b/cpp/src/Ice/LoggerAdminI.cpp index 92126e26048..3ae5d0f4e3d 100644 --- a/cpp/src/Ice/LoggerAdminI.cpp +++ b/cpp/src/Ice/LoggerAdminI.cpp @@ -40,7 +40,7 @@ class LoggerAdminI : public Ice::LoggerAdmin, vector log(const LogMessage&); - void deadRemoteLogger(const RemoteLoggerPrxPtr&, const LoggerPtr&, const LocalException&, const string&); + void deadRemoteLogger(const RemoteLoggerPrxPtr&, const LoggerPtr&, exception_ptr, const string&); int getTraceLevel() const { @@ -389,19 +389,12 @@ LoggerAdminI::attachRemoteLogger(shared_ptr prx, }, [self, logger, remoteLogger](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::LocalException& le) - { - self->deadRemoteLogger(remoteLogger, logger, le, "init"); - } + self->deadRemoteLogger(remoteLogger, logger, e, "init"); }); } - catch(const LocalException& ex) + catch(const LocalException&) { - deadRemoteLogger(remoteLogger, logger, ex, "init"); + deadRemoteLogger(remoteLogger, logger, current_exception(), "init"); throw; } } @@ -576,7 +569,7 @@ LoggerAdminI::log(const LogMessage& logMessage) void LoggerAdminI::deadRemoteLogger(const RemoteLoggerPrxPtr& remoteLogger, const LoggerPtr& logger, - const LocalException& ex, + std::exception_ptr ex, const string& operation) { // @@ -586,8 +579,15 @@ LoggerAdminI::deadRemoteLogger(const RemoteLoggerPrxPtr& remoteLogger, { if(_traceLevel > 0) { - Trace trace(logger, traceCategory); - trace << "detached `" << remoteLogger << "' because " << operation << " raised:\n" << ex; + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + Trace trace(logger, traceCategory); + trace << "detached `" << remoteLogger << "' because " << operation << " raised:\n" << e; + } } } } @@ -781,15 +781,15 @@ LoggerAdminLoggerI::run() { // expected if there are outstanding calls during communicator destruction } - catch(const LocalException& ex) + catch(const LocalException&) { - self->_loggerAdmin->deadRemoteLogger(remoteLogger, self->_localLogger, ex, "log"); + self->_loggerAdmin->deadRemoteLogger(remoteLogger, self->_localLogger, e, "log"); } }); } - catch(const LocalException& ex) + catch(const LocalException&) { - _loggerAdmin->deadRemoteLogger(*p, _localLogger, ex, "log"); + _loggerAdmin->deadRemoteLogger(*p, _localLogger, current_exception(), "log"); } } } diff --git a/cpp/src/Ice/ObserverHelper.cpp b/cpp/src/Ice/ObserverHelper.cpp index 3fe7e353a9f..fd99d055c3d 100644 --- a/cpp/src/Ice/ObserverHelper.cpp +++ b/cpp/src/Ice/ObserverHelper.cpp @@ -54,3 +54,19 @@ IceInternal::InvocationObserver::attach(IceInternal::Instance* instance, const s attach(obsv->getInvocationObserver(0, op, Ice::noExplicitContext)); } + +std::string IceInternal::getExceptionId(std::exception_ptr eptr) +{ + try + { + std::rethrow_exception(eptr); + } + catch (const Ice::Exception& ex) + { + return ex.ice_id(); + } + catch (const std::exception& ex) + { + return ex.what(); + } +} diff --git a/cpp/src/Ice/OutgoingAsync.cpp b/cpp/src/Ice/OutgoingAsync.cpp index 63ef7069f44..236571ab462 100644 --- a/cpp/src/Ice/OutgoingAsync.cpp +++ b/cpp/src/Ice/OutgoingAsync.cpp @@ -35,7 +35,7 @@ OutgoingAsyncBase::sent() } bool -OutgoingAsyncBase::exception(const Exception& ex) +OutgoingAsyncBase::exception(std::exception_ptr ex) { return exceptionImpl(ex); } @@ -169,7 +169,7 @@ OutgoingAsyncBase::invokeException() { try { - handleInvokeException(*_ex, this); + handleInvokeException(_ex, this); } catch(const std::exception& ex) { @@ -198,17 +198,13 @@ OutgoingAsyncBase::invokeResponse() { handleInvokeResponse(_state & OK, this); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - if(handleException(ex)) + if(handleException(current_exception())) { - handleInvokeException(ex, this); + handleInvokeException(current_exception(), this); } } - catch(const exception_ptr& ex) - { - rethrow_exception(ex); - } } catch(const std::exception& ex) { @@ -230,11 +226,11 @@ OutgoingAsyncBase::cancelable(const CancellationHandlerPtr& handler) { try { - _cancellationException->ice_throw(); + rethrow_exception(_cancellationException); } catch(const Ice::LocalException&) { - _cancellationException.reset(); + _cancellationException = nullptr; throw; } } @@ -244,7 +240,7 @@ OutgoingAsyncBase::cancelable(const CancellationHandlerPtr& handler) void OutgoingAsyncBase::cancel() { - cancel(Ice::InvocationCanceledException(__FILE__, __LINE__)); + cancel(make_exception_ptr(Ice::InvocationCanceledException(__FILE__, __LINE__))); } OutgoingAsyncBase::OutgoingAsyncBase(const InstancePtr& instance) : @@ -279,17 +275,17 @@ OutgoingAsyncBase::sentImpl(bool done) } bool -OutgoingAsyncBase::exceptionImpl(const Exception& ex) +OutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) { Lock sync(_m); - _ex = ex.ice_clone(); + _ex = ex; if(_childObserver) { - _childObserver.failed(ex.ice_id()); + _childObserver.failed(getExceptionId(ex)); _childObserver.detach(); } _cancellationHandler = 0; - _observer.failed(ex.ice_id()); + _observer.failed(getExceptionId(ex)); bool invoke = handleException(ex); if(!invoke) @@ -314,10 +310,10 @@ OutgoingAsyncBase::responseImpl(bool ok, bool invoke) { invoke &= handleResponse(ok); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - _ex = ex.ice_clone(); - invoke = handleException(ex); + _ex = current_exception(); + invoke = handleException(_ex); } if(!invoke) { @@ -327,14 +323,14 @@ OutgoingAsyncBase::responseImpl(bool ok, bool invoke) } void -OutgoingAsyncBase::cancel(const Ice::LocalException& ex) +OutgoingAsyncBase::cancel(std::exception_ptr ex) { CancellationHandlerPtr handler; { Lock sync(_m); if(!_cancellationHandler) { - _cancellationException = ex.ice_clone(); + _cancellationException = ex; return; } handler = _cancellationHandler; @@ -371,11 +367,11 @@ OutgoingAsyncBase::warning() const } bool -ProxyOutgoingAsyncBase::exception(const Exception& exc) +ProxyOutgoingAsyncBase::exception(std::exception_ptr exc) { if(_childObserver) { - _childObserver.failed(exc.ice_id()); + _childObserver.failed(getExceptionId(exc)); _childObserver.detach(); } @@ -399,9 +395,9 @@ ProxyOutgoingAsyncBase::exception(const Exception& exc) _instance->retryQueue()->add(shared_from_this(), _proxy->_handleException(exc, _handler, _mode, _sent, _cnt)); return false; } - catch(const Exception& ex) + catch(const Exception&) { - return exceptionImpl(ex); // No retries, we're done + return exceptionImpl(current_exception()); // No retries, we're done } } @@ -420,7 +416,7 @@ ProxyOutgoingAsyncBase::cancelable(const CancellationHandlerPtr& handler) } void -ProxyOutgoingAsyncBase::retryException(const Exception&) +ProxyOutgoingAsyncBase::retryException() { try { @@ -433,9 +429,9 @@ ProxyOutgoingAsyncBase::retryException(const Exception&) _proxy->_updateRequestHandler(_handler, 0); // Clear request handler and always retry. _instance->retryQueue()->add(shared_from_this(), 0); } - catch(const Ice::Exception& exc) + catch(const Ice::Exception&) { - if(exception(exc)) + if(exception(current_exception())) { invokeExceptionAsync(); } @@ -449,7 +445,7 @@ ProxyOutgoingAsyncBase::retry() } void -ProxyOutgoingAsyncBase::abort(const Ice::Exception& ex) +ProxyOutgoingAsyncBase::abort(std::exception_ptr ex) { assert(!_childObserver); @@ -457,14 +453,25 @@ ProxyOutgoingAsyncBase::abort(const Ice::Exception& ex) { invokeExceptionAsync(); } - else if(dynamic_cast(&ex)) + else { - // - // If it's a communicator destroyed exception, don't swallow - // it but instead notify the user thread. Even if no callback - // was provided. - // - ex.ice_throw(); + try + { + rethrow_exception(ex); + } + catch (const CommunicatorDestroyedException&) + { + // + // If it's a communicator destroyed exception, don't swallow + // it but instead notify the user thread. Even if no callback + // was provided. + // + throw; + } + catch (...) + { + // ignored. + } } } @@ -537,7 +544,7 @@ ProxyOutgoingAsyncBase::invokeImpl(bool userThread) _childObserver.failed(ex.ice_id()); _childObserver.detach(); } - int interval = _proxy->_handleException(ex, _handler, _mode, _sent, _cnt); + int interval = _proxy->_handleException(current_exception(), _handler, _mode, _sent, _cnt); if(interval > 0) { _instance->retryQueue()->add(shared_from_this(), interval); @@ -550,7 +557,7 @@ ProxyOutgoingAsyncBase::invokeImpl(bool userThread) } } } - catch(const Exception& ex) + catch(const Exception&) { // // If called from the user thread we re-throw, the exception @@ -560,7 +567,7 @@ ProxyOutgoingAsyncBase::invokeImpl(bool userThread) { throw; } - else if(exceptionImpl(ex)) // No retries, we're done + else if(exceptionImpl(current_exception())) // No retries, we're done { invokeExceptionAsync(); } @@ -582,7 +589,7 @@ ProxyOutgoingAsyncBase::sentImpl(bool done) } bool -ProxyOutgoingAsyncBase::exceptionImpl(const Exception& ex) +ProxyOutgoingAsyncBase::exceptionImpl(std::exception_ptr ex) { if(_proxy->_getReference()->getInvocationTimeout() != -1) { @@ -606,11 +613,11 @@ ProxyOutgoingAsyncBase::runTimerTask() { if(_proxy->_getReference()->getInvocationTimeout() == -2) { - cancel(ConnectionTimeoutException(__FILE__, __LINE__)); + cancel(make_exception_ptr(ConnectionTimeoutException(__FILE__, __LINE__))); } else { - cancel(InvocationTimeoutException(__FILE__, __LINE__)); + cancel(make_exception_ptr(InvocationTimeoutException(__FILE__, __LINE__))); } } @@ -840,9 +847,9 @@ OutgoingAsync::response() return responseImpl(replyStatus == replyOK, true); } - catch(const Exception& ex) + catch(const Exception&) { - return exception(ex); + return exception(current_exception()); } } @@ -860,7 +867,7 @@ OutgoingAsync::invokeCollocated(CollocatedRequestHandler* handler) } void -OutgoingAsync::abort(const Exception& ex) +OutgoingAsync::abort(std::exception_ptr ex) { const Reference::Mode mode = _proxy->_getReference()->getMode(); if(mode == Reference::ModeBatchOneway || mode == Reference::ModeBatchDatagram) @@ -918,9 +925,9 @@ OutgoingAsync::invoke(const string& operation, } invoke(operation); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - abort(ex); + abort(current_exception()); } } @@ -950,7 +957,7 @@ LambdaInvoke::handleSent(bool, bool alreadySent) } bool -LambdaInvoke::handleException(const Ice::Exception&) +LambdaInvoke::handleException(std::exception_ptr) { return _exception != nullptr; // Invoke the callback } @@ -968,16 +975,9 @@ LambdaInvoke::handleInvokeSent(bool sentSynchronously, OutgoingAsyncBase*) const } void -LambdaInvoke::handleInvokeException(const Ice::Exception& ex, OutgoingAsyncBase*) const +LambdaInvoke::handleInvokeException(std::exception_ptr ex, OutgoingAsyncBase*) const { - try - { - ex.ice_throw(); - } - catch(const Ice::Exception&) - { - _exception(current_exception()); - } + _exception(ex); } void diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp index a025a3f7aed..a11ad778a40 100644 --- a/cpp/src/Ice/Proxy.cpp +++ b/cpp/src/Ice/Proxy.cpp @@ -442,7 +442,7 @@ Ice::ObjectPrx::ice_getCachedConnection() const } int -Ice::ObjectPrx::_handleException(const Exception& ex, +Ice::ObjectPrx::_handleException(std::exception_ptr ex, const RequestHandlerPtr& handler, OperationMode mode, bool sent, @@ -465,28 +465,35 @@ Ice::ObjectPrx::_handleException(const Exception& ex, // If the request didn't get sent or if it's non-mutating or idempotent it can // also always be retried if the retry count isn't reached. // - const LocalException* localEx = dynamic_cast(&ex); - if(localEx && (!sent || - mode == OperationMode::Nonmutating || mode == OperationMode::Idempotent || - dynamic_cast(&ex) || - dynamic_cast(&ex))) + + try { - try + rethrow_exception(ex); + } + catch (const Ice::LocalException& localEx) + { + if (!sent || + mode == OperationMode::Nonmutating || mode == OperationMode::Idempotent || + dynamic_cast(&localEx) || + dynamic_cast(&localEx)) { - return _reference->getInstance()->proxyFactory()->checkRetryAfterException(*localEx, _reference, cnt); + try + { + return _reference->getInstance()->proxyFactory()->checkRetryAfterException(ex, _reference, cnt); + } + catch (const CommunicatorDestroyedException&) + { + // + // The communicator is already destroyed, so we cannot retry. + // + rethrow_exception(ex); + } } - catch(const CommunicatorDestroyedException&) + else { - // - // The communicator is already destroyed, so we cannot retry. - // - ex.ice_throw(); + throw; // Retry could break at-most-once semantics, don't retry. } } - else - { - ex.ice_throw(); // Retry could break at-most-once semantics, don't retry. - } return 0; // Keep the compiler happy. } diff --git a/cpp/src/Ice/ProxyFactory.cpp b/cpp/src/Ice/ProxyFactory.cpp index 034790074d0..af007a3e445 100644 --- a/cpp/src/Ice/ProxyFactory.cpp +++ b/cpp/src/Ice/ProxyFactory.cpp @@ -87,7 +87,7 @@ IceInternal::ProxyFactory::referenceToProxy(const ReferencePtr& ref) const } int -IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, const ReferencePtr& ref, int& cnt) const +IceInternal::ProxyFactory::checkRetryAfterException(std::exception_ptr ex, const ReferencePtr& ref, int& cnt) const { TraceLevelsPtr traceLevels = _instance->traceLevels(); LoggerPtr logger = _instance->initializationData().logger; @@ -99,7 +99,7 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co // if(ref->getMode() == Reference::ModeBatchOneway || ref->getMode() == Reference::ModeBatchDatagram) { - ex.ice_throw(); + rethrow_exception(ex); } // @@ -108,13 +108,18 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co // if(dynamic_cast(ref.get())) { - ex.ice_throw(); + rethrow_exception(ex); } - const ObjectNotExistException* one = dynamic_cast(&ex); - if(one) + bool isCloseConnectionException = false; + string errorMessage; + try { - if(ref->getRouterInfo() && one->operation == "ice_add_proxy") + rethrow_exception(ex); + } + catch (const ObjectNotExistException& one) + { + if(ref->getRouterInfo() && one.operation == "ice_add_proxy") { // // If we have a router, an ObjectNotExistException with an @@ -130,7 +135,7 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co if(traceLevels->retry >= 1) { Trace out(logger, traceLevels->retryCat); - out << "retrying operation call to add proxy to router\n" << ex; + out << "retrying operation call to add proxy to router\n" << one; } return 0; // We must always retry, so we don't look at the retry count. @@ -157,69 +162,80 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co // For all other cases, we don't retry // ObjectNotExistException. // - ex.ice_throw(); + throw; } } - else if(dynamic_cast(&ex)) + catch (const RequestFailedException&) { // // We don't retry other *NotExistException, which are all // derived from RequestFailedException. // - ex.ice_throw(); + throw; } - - // - // There is no point in retrying an operation that resulted in a - // MarshalException. This must have been raised locally (because - // if it happened in a server it would result in an - // UnknownLocalException instead), which means there was a problem - // in this process that will not change if we try again. - // - // The most likely cause for a MarshalException is exceeding the - // maximum message size, which is represented by the subclass - // MemoryLimitException. For example, a client can attempt to send - // a message that exceeds the maximum memory size, or accumulate - // enough batch requests without flushing that the maximum size is - // reached. - // - // This latter case is especially problematic, because if we were - // to retry a batch request after a MarshalException, we would in - // fact silently discard the accumulated requests and allow new - // batch requests to accumulate. If the subsequent batched - // requests do not exceed the maximum message size, it appears to - // the client that all of the batched requests were accepted, when - // in reality only the last few are actually sent. - // - if(dynamic_cast(&ex)) + catch (const MarshalException&) { - ex.ice_throw(); + // + // There is no point in retrying an operation that resulted in a + // MarshalException. This must have been raised locally (because + // if it happened in a server it would result in an + // UnknownLocalException instead), which means there was a problem + // in this process that will not change if we try again. + // + // The most likely cause for a MarshalException is exceeding the + // maximum message size, which is represented by the subclass + // MemoryLimitException. For example, a client can attempt to send + // a message that exceeds the maximum memory size, or accumulate + // enough batch requests without flushing that the maximum size is + // reached. + // + // This latter case is especially problematic, because if we were + // to retry a batch request after a MarshalException, we would in + // fact silently discard the accumulated requests and allow new + // batch requests to accumulate. If the subsequent batched + // requests do not exceed the maximum message size, it appears to + // the client that all of the batched requests were accepted, when + // in reality only the last few are actually sent. + // + throw; } - - // - // Don't retry if the communicator is destroyed, object adapter is deactivated, - // or connection is manually closed. - // - if(dynamic_cast(&ex) || - dynamic_cast(&ex) || - dynamic_cast(&ex)) + catch (const CommunicatorDestroyedException&) { - ex.ice_throw(); + throw; } - - // - // Don't retry invocation timeouts. - // - if(dynamic_cast(&ex) || dynamic_cast(&ex)) + catch (const ObjectAdapterDeactivatedException&) + { + throw; + } + catch (const Ice::ConnectionManuallyClosedException&) + { + throw; + } + catch (const InvocationTimeoutException&) + { + throw; + } + catch (const InvocationCanceledException&) + { + throw; + } + catch (const CloseConnectionException& e) + { + isCloseConnectionException = true; + errorMessage = e.what(); + // and retry + } + catch (const std::exception& e) { - ex.ice_throw(); + errorMessage = e.what(); + // We retry on all other exceptions! } ++cnt; assert(cnt > 0); int interval = -1; - if(cnt == static_cast(_retryIntervals.size() + 1) && dynamic_cast(&ex)) + if(cnt == static_cast(_retryIntervals.size() + 1) && isCloseConnectionException) { // // A close connection exception is always retried at least once, even if the retry @@ -232,9 +248,9 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co if(traceLevels->retry >= 1) { Trace out(logger, traceLevels->retryCat); - out << "cannot retry operation call because retry limit has been exceeded\n" << ex; + out << "cannot retry operation call because retry limit has been exceeded\n" << errorMessage; } - ex.ice_throw(); + rethrow_exception(ex); } else { @@ -249,7 +265,7 @@ IceInternal::ProxyFactory::checkRetryAfterException(const LocalException& ex, co { out << " in " << interval << "ms"; } - out << " because of exception\n" << ex; + out << " because of exception\n" << errorMessage; } return interval; } diff --git a/cpp/src/Ice/ProxyFactory.h b/cpp/src/Ice/ProxyFactory.h index e04444d12a0..6572208b409 100644 --- a/cpp/src/Ice/ProxyFactory.h +++ b/cpp/src/Ice/ProxyFactory.h @@ -39,7 +39,7 @@ class ProxyFactory Ice::ObjectPrxPtr referenceToProxy(const ReferencePtr&) const; - int checkRetryAfterException(const Ice::LocalException&, const ReferencePtr&, int&) const; + int checkRetryAfterException(std::exception_ptr, const ReferencePtr&, int&) const; private: diff --git a/cpp/src/Ice/Reference.cpp b/cpp/src/Ice/Reference.cpp index 790e218a12c..a1be2d9ca69 100644 --- a/cpp/src/Ice/Reference.cpp +++ b/cpp/src/Ice/Reference.cpp @@ -1431,7 +1431,7 @@ IceInternal::RoutableReference::getConnection(const GetConnectionCallbackPtr& ca _reference->getConnectionNoRouterInfo(_callback); } - void setException(const Ice::LocalException& ex) final + void setException(std::exception_ptr ex) final { _callback->setException(ex); } @@ -1479,15 +1479,15 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal _callback->setConnection(connection, compress); } - void setException(const Ice::LocalException& exc) final + void setException(std::exception_ptr exc) final { try { - exc.ice_throw(); + rethrow_exception(exc); } - catch(const Ice::NoEndpointException& ex) + catch(const Ice::NoEndpointException&) { - _callback->setException(ex); // No need to retry if there's no endpoints. + _callback->setException(exc); // No need to retry if there's no endpoints. } catch(const Ice::LocalException& ex) { @@ -1506,7 +1506,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal _reference->getConnectionNoRouterInfo(_callback); // Retry. return; } - _callback->setException(ex); + _callback->setException(exc); } } @@ -1526,7 +1526,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal { if(endpoints.empty()) { - _callback->setException(Ice::NoEndpointException(__FILE__, __LINE__, _reference->toString())); + _callback->setException(make_exception_ptr(Ice::NoEndpointException(__FILE__, __LINE__, _reference->toString()))); return; } @@ -1535,7 +1535,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal _reference->createConnection(endpts, make_shared(_reference, _callback, cached)); } - void setException(const Ice::LocalException& ex) final + void setException(std::exception_ptr ex) final { _callback->setException(ex); } @@ -1565,7 +1565,7 @@ IceInternal::RoutableReference::getConnectionNoRouterInfo(const GetConnectionCal } else { - callback->setException(Ice::NoEndpointException(__FILE__, __LINE__, toString())); + callback->setException(make_exception_ptr(Ice::NoEndpointException(__FILE__, __LINE__, toString()))); } } @@ -1576,7 +1576,7 @@ IceInternal::RoutableReference::createConnection(const vector& all vector endpoints = filterEndpoints(allEndpoints); if(endpoints.empty()) { - callback->setException(Ice::NoEndpointException(__FILE__, __LINE__, toString())); + callback->setException(make_exception_ptr(Ice::NoEndpointException(__FILE__, __LINE__, toString()))); return; } @@ -1604,7 +1604,7 @@ IceInternal::RoutableReference::createConnection(const vector& all _callback->setConnection(connection, compress); } - void setException(const Ice::LocalException& ex) final + void setException(std::exception_ptr ex) final { _callback->setException(ex); } @@ -1649,16 +1649,16 @@ IceInternal::RoutableReference::createConnection(const vector& all _callback->setConnection(connection, compress); } - void setException(const Ice::LocalException& ex) final + void setException(std::exception_ptr ex) final { if(!_exception) { - _exception = ex.ice_clone(); + _exception = ex; } if(++_i == _endpoints.size()) { - _callback->setException(*_exception); + _callback->setException(_exception); return; } @@ -1685,7 +1685,7 @@ IceInternal::RoutableReference::createConnection(const vector& all const vector _endpoints; const GetConnectionCallbackPtr _callback; size_t _i; - unique_ptr _exception; + exception_ptr _exception; }; // diff --git a/cpp/src/Ice/Reference.h b/cpp/src/Ice/Reference.h index 9be76217186..29c2cb0524e 100644 --- a/cpp/src/Ice/Reference.h +++ b/cpp/src/Ice/Reference.h @@ -44,7 +44,7 @@ class Reference : public std::enable_shared_from_this public: virtual void setConnection(const Ice::ConnectionIPtr&, bool) = 0; - virtual void setException(const Ice::LocalException&) = 0; + virtual void setException(std::exception_ptr) = 0; }; using GetConnectionCallbackPtr = std::shared_ptr; diff --git a/cpp/src/Ice/RequestHandler.cpp b/cpp/src/Ice/RequestHandler.cpp index a50c89a5688..a9f764cb105 100644 --- a/cpp/src/Ice/RequestHandler.cpp +++ b/cpp/src/Ice/RequestHandler.cpp @@ -8,21 +8,20 @@ using namespace std; using namespace IceInternal; -RetryException::RetryException(const Ice::LocalException& ex) +RetryException::RetryException(exception_ptr ex) { - _ex = ex.ice_clone(); + _ex = ex; } RetryException::RetryException(const RetryException& ex) { - _ex = ex.get()->ice_clone(); + _ex = ex.get(); } -const Ice::LocalException* +exception_ptr RetryException::get() const { - assert(_ex.get()); - return _ex.get(); + return _ex; } RequestHandler::RequestHandler(const ReferencePtr& reference) : diff --git a/cpp/src/Ice/RequestHandler.h b/cpp/src/Ice/RequestHandler.h index 9675389594f..96d6d0aeb43 100644 --- a/cpp/src/Ice/RequestHandler.h +++ b/cpp/src/Ice/RequestHandler.h @@ -31,21 +31,21 @@ class RetryException { public: - RetryException(const Ice::LocalException&); + RetryException(std::exception_ptr); RetryException(const RetryException&); - const Ice::LocalException* get() const; + std::exception_ptr get() const; private: - std::unique_ptr _ex; + std::exception_ptr _ex; }; class CancellationHandler { public: - virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, const Ice::LocalException&) = 0; + virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, std::exception_ptr) = 0; }; class RequestHandler : public CancellationHandler diff --git a/cpp/src/Ice/ResponseHandler.h b/cpp/src/Ice/ResponseHandler.h index 6eee46e6942..128656e1cda 100644 --- a/cpp/src/Ice/ResponseHandler.h +++ b/cpp/src/Ice/ResponseHandler.h @@ -29,8 +29,8 @@ class ResponseHandler : public EnableSharedFromThis virtual void sendResponse(Ice::Int, Ice::OutputStream*, Ice::Byte, bool) = 0; virtual void sendNoResponse() = 0; - virtual bool systemException(Ice::Int, const Ice::SystemException&, bool) = 0; - virtual void invokeException(Ice::Int, const Ice::LocalException&, int, bool) = 0; + virtual bool systemException(Ice::Int, std::exception_ptr, bool) = 0; + virtual void invokeException(Ice::Int, std::exception_ptr, int, bool) = 0; }; } diff --git a/cpp/src/Ice/RetryQueue.cpp b/cpp/src/Ice/RetryQueue.cpp index 2be540624d6..624f365f369 100644 --- a/cpp/src/Ice/RetryQueue.cpp +++ b/cpp/src/Ice/RetryQueue.cpp @@ -39,14 +39,21 @@ IceInternal::RetryTask::runTimerTask() } void -IceInternal::RetryTask::asyncRequestCanceled(const OutgoingAsyncBasePtr& /*outAsync*/, const Ice::LocalException& ex) +IceInternal::RetryTask::asyncRequestCanceled(const OutgoingAsyncBasePtr& /*outAsync*/, exception_ptr ex) { if(_queue->cancel(shared_from_this())) { if(_instance->traceLevels()->retry >= 1) { - Trace out(_instance->initializationData().logger, _instance->traceLevels()->retryCat); - out << "operation retry canceled\n" << ex; + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + Trace out(_instance->initializationData().logger, _instance->traceLevels()->retryCat); + out << "operation retry canceled\n" << e; + } } if(_outAsync->exception(ex)) { @@ -60,7 +67,7 @@ IceInternal::RetryTask::destroy() { try { - _outAsync->abort(CommunicatorDestroyedException(__FILE__, __LINE__)); + _outAsync->abort(make_exception_ptr(CommunicatorDestroyedException(__FILE__, __LINE__))); } catch(const CommunicatorDestroyedException&) { diff --git a/cpp/src/Ice/RetryQueue.h b/cpp/src/Ice/RetryQueue.h index 5c536ded68c..7cbdebb50da 100644 --- a/cpp/src/Ice/RetryQueue.h +++ b/cpp/src/Ice/RetryQueue.h @@ -27,7 +27,7 @@ class RetryTask : public IceUtil::TimerTask, virtual void runTimerTask(); - virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, const Ice::LocalException&); + virtual void asyncRequestCanceled(const OutgoingAsyncBasePtr&, std::exception_ptr); void destroy(); diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp index 1df4214ad3a..cc4e953bcf5 100644 --- a/cpp/src/Ice/RouterInfo.cpp +++ b/cpp/src/Ice/RouterInfo.cpp @@ -152,10 +152,10 @@ IceInternal::RouterInfo::getClientProxyResponse(const Ice::ObjectPrxPtr& proxy, } void -IceInternal::RouterInfo::getClientProxyException(const Ice::Exception& ex, +IceInternal::RouterInfo::getClientProxyException(std::exception_ptr ex, const GetClientEndpointsCallbackPtr& callback) { - callback->setException(dynamic_cast(ex)); + callback->setException(ex); } void @@ -181,14 +181,7 @@ IceInternal::RouterInfo::getClientEndpoints(const GetClientEndpointsCallbackPtr& }, [self, callback](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - self->getClientProxyException(ex, callback); - } + self->getClientProxyException(e, callback); }); } @@ -212,9 +205,9 @@ IceInternal::RouterInfo::addProxyResponse(const Ice::ObjectProxySeq& proxies, co } void -IceInternal::RouterInfo::addProxyException(const Ice::Exception& ex, const AddProxyCookiePtr& cookie) +IceInternal::RouterInfo::addProxyException(std::exception_ptr ex, const AddProxyCookiePtr& cookie) { - cookie->cb()->setException(dynamic_cast(ex)); + cookie->cb()->setException(ex); } bool @@ -248,14 +241,7 @@ IceInternal::RouterInfo::addProxy(const Ice::ObjectPrxPtr& proxy, const AddProxy }, [self, cookie](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - self->addProxyException(ex, cookie); - } + self->addProxyException(e, cookie); }); return false; } diff --git a/cpp/src/Ice/RouterInfo.h b/cpp/src/Ice/RouterInfo.h index adf0306c8f9..6694005dfc5 100644 --- a/cpp/src/Ice/RouterInfo.h +++ b/cpp/src/Ice/RouterInfo.h @@ -55,7 +55,7 @@ class RouterInfo final : public std::enable_shared_from_this public: virtual void setEndpoints(const std::vector&) = 0; - virtual void setException(const Ice::LocalException&) = 0; + virtual void setException(std::exception_ptr) = 0; }; using GetClientEndpointsCallbackPtr = std::shared_ptr; @@ -64,7 +64,7 @@ class RouterInfo final : public std::enable_shared_from_this public: virtual void addedProxy() = 0; - virtual void setException(const Ice::LocalException&) = 0; + virtual void setException(std::exception_ptr) = 0; }; using AddProxyCallbackPtr = std::shared_ptr; @@ -84,7 +84,7 @@ class RouterInfo final : public std::enable_shared_from_this } void getClientProxyResponse(const Ice::ObjectPrxPtr&, const std::optional&, const GetClientEndpointsCallbackPtr&); - void getClientProxyException(const Ice::Exception&, const GetClientEndpointsCallbackPtr&); + void getClientProxyException(std::exception_ptr, const GetClientEndpointsCallbackPtr&); std::vector getClientEndpoints(); void getClientEndpoints(const GetClientEndpointsCallbackPtr&); std::vector getServerEndpoints(); @@ -117,7 +117,7 @@ class RouterInfo final : public std::enable_shared_from_this using AddProxyCookiePtr = std::shared_ptr; void addProxyResponse(const Ice::ObjectProxySeq&, const AddProxyCookiePtr&); - void addProxyException(const Ice::Exception&, const AddProxyCookiePtr&); + void addProxyException(std::exception_ptr, const AddProxyCookiePtr&); bool addProxy(const Ice::ObjectPrxPtr&, const AddProxyCallbackPtr&); void setAdapter(const Ice::ObjectAdapterPtr&); diff --git a/cpp/src/Ice/TcpTransceiver.cpp b/cpp/src/Ice/TcpTransceiver.cpp index 13dc90fb1f9..db31fe2e299 100644 --- a/cpp/src/Ice/TcpTransceiver.cpp +++ b/cpp/src/Ice/TcpTransceiver.cpp @@ -30,7 +30,7 @@ IceInternal::TcpTransceiver::initialize(Buffer& readBuffer, Buffer& writeBuffer) } SocketOperation -IceInternal::TcpTransceiver::closing(bool initiator, const Ice::LocalException&) +IceInternal::TcpTransceiver::closing(bool initiator, exception_ptr) { // If we are initiating the connection closure, wait for the peer // to close the TCP/IP connection. Otherwise, close immediately. diff --git a/cpp/src/Ice/TcpTransceiver.h b/cpp/src/Ice/TcpTransceiver.h index f0db09b989a..a77b3bc218b 100644 --- a/cpp/src/Ice/TcpTransceiver.h +++ b/cpp/src/Ice/TcpTransceiver.h @@ -25,7 +25,7 @@ class TcpTransceiver final : public Transceiver NativeInfoPtr getNativeInfo() final; SocketOperation initialize(Buffer&, Buffer&) final; - SocketOperation closing(bool, const Ice::LocalException&) final; + SocketOperation closing(bool, std::exception_ptr) final; void close() final; SocketOperation write(Buffer&) final; diff --git a/cpp/src/Ice/Transceiver.h b/cpp/src/Ice/Transceiver.h index a11aeba1ca6..6d1621642cf 100644 --- a/cpp/src/Ice/Transceiver.h +++ b/cpp/src/Ice/Transceiver.h @@ -23,7 +23,7 @@ class ICE_API Transceiver virtual NativeInfoPtr getNativeInfo() = 0; virtual SocketOperation initialize(Buffer&, Buffer&) = 0; - virtual SocketOperation closing(bool, const Ice::LocalException&) = 0; + virtual SocketOperation closing(bool, std::exception_ptr) = 0; virtual void close() = 0; virtual EndpointIPtr bind(); diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp index 82b082fffbd..7ae88081396 100644 --- a/cpp/src/Ice/UdpTransceiver.cpp +++ b/cpp/src/Ice/UdpTransceiver.cpp @@ -62,7 +62,7 @@ IceInternal::UdpTransceiver::initialize(Buffer& /*readBuffer*/, Buffer& /*writeB } SocketOperation -IceInternal::UdpTransceiver::closing(bool, const Ice::LocalException&) +IceInternal::UdpTransceiver::closing(bool, exception_ptr) { // Nothing to do. return SocketOperationNone; diff --git a/cpp/src/Ice/UdpTransceiver.h b/cpp/src/Ice/UdpTransceiver.h index 41d72c181d2..e4662d7478d 100644 --- a/cpp/src/Ice/UdpTransceiver.h +++ b/cpp/src/Ice/UdpTransceiver.h @@ -38,7 +38,7 @@ class UdpTransceiver final : public Transceiver, public NativeInfo, public std:: #endif SocketOperation initialize(Buffer&, Buffer&) final; - SocketOperation closing(bool, const Ice::LocalException&) final; + SocketOperation closing(bool, std::exception_ptr) final; void close() final; EndpointIPtr bind() final; SocketOperation write(Buffer&) final; diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp index 287694e9ef2..4c8b71be2dd 100644 --- a/cpp/src/Ice/WSEndpoint.cpp +++ b/cpp/src/Ice/WSEndpoint.cpp @@ -237,7 +237,7 @@ IceInternal::WSEndpoint::connectors_async(EndpointSelectionType selType, _callback->connectors(connectors); } - virtual void exception(const LocalException& ex) + virtual void exception(std::exception_ptr ex) { _callback->exception(ex); } diff --git a/cpp/src/Ice/WSTransceiver.cpp b/cpp/src/Ice/WSTransceiver.cpp index 3dd791f8a49..685ff4da05a 100644 --- a/cpp/src/Ice/WSTransceiver.cpp +++ b/cpp/src/Ice/WSTransceiver.cpp @@ -356,7 +356,7 @@ IceInternal::WSTransceiver::initialize(Buffer& readBuffer, Buffer& writeBuffer) } SocketOperation -IceInternal::WSTransceiver::closing(bool initiator, const Ice::LocalException& reason) +IceInternal::WSTransceiver::closing(bool initiator, exception_ptr reason) { if(_instance->traceLevel() >= 1) { @@ -387,23 +387,34 @@ IceInternal::WSTransceiver::closing(bool initiator, const Ice::LocalException& r _closingInitiator = initiator; - if(dynamic_cast(&reason)) + try + { + rethrow_exception(reason); + } + catch (const Ice::CloseConnectionException&) { _closingReason = CLOSURE_NORMAL; } - else if(dynamic_cast(&reason) || - dynamic_cast(&reason)) + catch (const Ice::ObjectAdapterDeactivatedException&) { _closingReason = CLOSURE_SHUTDOWN; } - else if(dynamic_cast(&reason)) + catch (const Ice::CommunicatorDestroyedException&) { - _closingReason = CLOSURE_PROTOCOL_ERROR; + _closingReason = CLOSURE_SHUTDOWN; } - else if(dynamic_cast(&reason)) + catch (const Ice::MemoryLimitException&) { _closingReason = CLOSURE_TOO_BIG; } + catch (const Ice::ProtocolException&) + { + _closingReason = CLOSURE_PROTOCOL_ERROR; + } + catch (...) + { + // no closing reason + } if(_state == StateOpened) { diff --git a/cpp/src/Ice/WSTransceiver.h b/cpp/src/Ice/WSTransceiver.h index 09f5c0df01c..8886c5e61ff 100644 --- a/cpp/src/Ice/WSTransceiver.h +++ b/cpp/src/Ice/WSTransceiver.h @@ -33,7 +33,7 @@ class WSTransceiver final : public Transceiver #endif SocketOperation initialize(Buffer&, Buffer&) final; - SocketOperation closing(bool, const Ice::LocalException&) final; + SocketOperation closing(bool, std::exception_ptr) final; void close() final; SocketOperation write(Buffer&) final; SocketOperation read(Buffer&) final; diff --git a/cpp/src/Ice/ios/StreamTransceiver.cpp b/cpp/src/Ice/ios/StreamTransceiver.cpp index d6c92051e26..65dabaebf9f 100644 --- a/cpp/src/Ice/ios/StreamTransceiver.cpp +++ b/cpp/src/Ice/ios/StreamTransceiver.cpp @@ -286,7 +286,7 @@ IceObjC::StreamTransceiver::initialize(Buffer& /*readBuffer*/, Buffer& /*writeBu } SocketOperation -IceObjC::StreamTransceiver::closing(bool initiator, const Ice::LocalException&) +IceObjC::StreamTransceiver::closing(bool initiator, exception_ptr) { // If we are initiating the connection closure, wait for the peer // to close the TCP/IP connection. Otherwise, close immediately. diff --git a/cpp/src/Ice/ios/StreamTransceiver.h b/cpp/src/Ice/ios/StreamTransceiver.h index 391ea2adfc2..69481930cca 100644 --- a/cpp/src/Ice/ios/StreamTransceiver.h +++ b/cpp/src/Ice/ios/StreamTransceiver.h @@ -53,7 +53,7 @@ class StreamTransceiver : public IceInternal::Transceiver, public IceInternal::S virtual void closeStreams(); virtual IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&); - virtual IceInternal::SocketOperation closing(bool, const Ice::LocalException&); + virtual IceInternal::SocketOperation closing(bool, std::exception_ptr); virtual void close(); virtual IceInternal::SocketOperation write(IceInternal::Buffer&); diff --git a/cpp/src/IceBT/Engine.cpp b/cpp/src/IceBT/Engine.cpp index 6436c585519..42c60891017 100644 --- a/cpp/src/IceBT/Engine.cpp +++ b/cpp/src/IceBT/Engine.cpp @@ -1206,12 +1206,12 @@ class BluetoothService : public DBus::Filter, public std::enable_shared_from_thi catch(const DBus::Exception& ex) { ok = false; - cb->failed(BluetoothException(__FILE__, __LINE__, ex.reason)); + cb->failed(make_exception_ptr(BluetoothException(__FILE__, __LINE__, ex.reason))); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { ok = false; - cb->failed(ex); + cb->failed(current_exception()); } // diff --git a/cpp/src/IceBT/Engine.h b/cpp/src/IceBT/Engine.h index 99370a73b24..6e0aa697afc 100644 --- a/cpp/src/IceBT/Engine.h +++ b/cpp/src/IceBT/Engine.h @@ -46,7 +46,7 @@ class ConnectCallback public: virtual void completed(int, const ConnectionPtr&) = 0; - virtual void failed(const Ice::LocalException&) = 0; + virtual void failed(std::exception_ptr) = 0; }; using ConnectCallbackPtr = std::shared_ptr; diff --git a/cpp/src/IceBT/TransceiverI.cpp b/cpp/src/IceBT/TransceiverI.cpp index d1b2be8afaa..7af5f9846d0 100644 --- a/cpp/src/IceBT/TransceiverI.cpp +++ b/cpp/src/IceBT/TransceiverI.cpp @@ -33,7 +33,7 @@ IceBT::TransceiverI::initialize(IceInternal::Buffer& /*readBuffer*/, IceInternal // // Raise the stored exception from a failed connection attempt. // - _exception->ice_throw(); + rethrow_exception(_exception); } else if(_needConnect) { @@ -49,7 +49,7 @@ IceBT::TransceiverI::initialize(IceInternal::Buffer& /*readBuffer*/, IceInternal } IceInternal::SocketOperation -IceBT::TransceiverI::closing(bool initiator, const Ice::LocalException&) +IceBT::TransceiverI::closing(bool initiator, exception_ptr) { // // If we are initiating the connection closure, wait for the peer @@ -176,13 +176,13 @@ IceBT::TransceiverI::connectCompleted(int fd, const ConnectionPtr& conn) } void -IceBT::TransceiverI::connectFailed(const Ice::LocalException& ex) +IceBT::TransceiverI::connectFailed(std::exception_ptr ex) { lock_guard lock(_mutex); // // Save the exception - it will be raised in initialize(). // - _exception = ex.ice_clone(); + _exception = ex; // // Triggers a call to write() from a different thread. // diff --git a/cpp/src/IceBT/TransceiverI.h b/cpp/src/IceBT/TransceiverI.h index 07c8c38d4bb..75913813c63 100644 --- a/cpp/src/IceBT/TransceiverI.h +++ b/cpp/src/IceBT/TransceiverI.h @@ -27,7 +27,7 @@ class TransceiverI final : public IceInternal::Transceiver, public std::enable_s IceInternal::NativeInfoPtr getNativeInfo() final; IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close() final; IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; @@ -46,10 +46,10 @@ class TransceiverI final : public IceInternal::Transceiver, public std::enable_s std::string _addr; std::string _uuid; bool _needConnect; - std::unique_ptr _exception; + std::exception_ptr _exception; std::mutex _mutex; void connectCompleted(int, const ConnectionPtr&); - void connectFailed(const Ice::LocalException&); + void connectFailed(std::exception_ptr); class ConnectCallbackI final : public ConnectCallback { @@ -65,7 +65,7 @@ class TransceiverI final : public IceInternal::Transceiver, public std::enable_s _transceiver->connectCompleted(fd, conn); } - void failed(const Ice::LocalException& ex) final + void failed(std::exception_ptr ex) final { _transceiver->connectFailed(ex); } diff --git a/cpp/src/IceDiscovery/LookupI.cpp b/cpp/src/IceDiscovery/LookupI.cpp index 9b4792305de..ee94623215f 100644 --- a/cpp/src/IceDiscovery/LookupI.cpp +++ b/cpp/src/IceDiscovery/LookupI.cpp @@ -125,14 +125,7 @@ AdapterRequest::invokeWithLookup(const string& domainId, const LookupPrxPtr& loo auto self = shared_from_this(); lookup->findAdapterByIdAsync(domainId, _id, lookupReply, nullptr, [self](exception_ptr ex) { - try - { - rethrow_exception(ex); - } - catch(const Ice::LocalException& e) - { - self->_lookup->adapterRequestException(self, e); - } + self->_lookup->adapterRequestException(self, ex); }); } @@ -159,14 +152,7 @@ ObjectRequest::invokeWithLookup(const string& domainId, const LookupPrxPtr& look auto self = shared_from_this(); lookup->findObjectByIdAsync(domainId, _id, lookupReply, nullptr, [self](exception_ptr ex) { - try - { - rethrow_exception(ex); - } - catch(const Ice::LocalException& e) - { - self->_lookup->objectRequestException(self, e); - } + self->_lookup->objectRequestException(self, ex); }); } @@ -418,7 +404,7 @@ LookupI::objectRequestTimedOut(const ObjectRequestPtr& request) } void -LookupI::adapterRequestException(const AdapterRequestPtr& request, const LocalException& ex) +LookupI::adapterRequestException(const AdapterRequestPtr& request, exception_ptr ex) { lock_guard lock(_mutex); map::iterator p = _adapterRequests.find(request->getId()); @@ -431,9 +417,17 @@ LookupI::adapterRequestException(const AdapterRequestPtr& request, const LocalEx { if(_warnOnce) { - Warning warn(_lookup->ice_getCommunicator()->getLogger()); - warn << "failed to lookup adapter `" << p->first << "' with lookup proxy `" << _lookup << "':\n" << ex; - _warnOnce = false; + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + Warning warn(_lookup->ice_getCommunicator()->getLogger()); + warn << "failed to lookup adapter `" << p->first << "' with lookup proxy `" << _lookup << "':\n" << e; + _warnOnce = false; + } + } _timer->cancel(request); _adapterRequests.erase(p); @@ -469,7 +463,7 @@ LookupI::adapterRequestTimedOut(const AdapterRequestPtr& request) } void -LookupI::objectRequestException(const ObjectRequestPtr& request, const LocalException& ex) +LookupI::objectRequestException(const ObjectRequestPtr& request, exception_ptr ex) { lock_guard lock(_mutex); map::iterator p = _objectRequests.find(request->getId()); @@ -482,10 +476,17 @@ LookupI::objectRequestException(const ObjectRequestPtr& request, const LocalExce { if(_warnOnce) { - Warning warn(_lookup->ice_getCommunicator()->getLogger()); - string id = _lookup->ice_getCommunicator()->identityToString(p->first); - warn << "failed to lookup object `" << id << "' with lookup proxy `" << _lookup << "':\n" << ex; - _warnOnce = false; + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + Warning warn(_lookup->ice_getCommunicator()->getLogger()); + string id = _lookup->ice_getCommunicator()->identityToString(p->first); + warn << "failed to lookup object `" << id << "' with lookup proxy `" << _lookup << "':\n" << e; + _warnOnce = false; + } } _timer->cancel(request); _objectRequests.erase(p); diff --git a/cpp/src/IceDiscovery/LookupI.h b/cpp/src/IceDiscovery/LookupI.h index eebf2524f9d..158d75d757f 100644 --- a/cpp/src/IceDiscovery/LookupI.h +++ b/cpp/src/IceDiscovery/LookupI.h @@ -147,9 +147,9 @@ class LookupI : public Lookup, public std::enable_shared_from_this void foundAdapter(const std::string&, const std::string&, const Ice::ObjectPrxPtr&, bool); void adapterRequestTimedOut(const AdapterRequestPtr&); - void adapterRequestException(const AdapterRequestPtr&, const Ice::LocalException&); + void adapterRequestException(const AdapterRequestPtr&, std::exception_ptr); void objectRequestTimedOut(const ObjectRequestPtr&); - void objectRequestException(const ObjectRequestPtr&, const Ice::LocalException&); + void objectRequestException(const ObjectRequestPtr&, std::exception_ptr); const IceUtil::TimerPtr& timer() diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index d5a04e40f60..2c61a2bfc36 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -589,9 +589,9 @@ Parser::addApplication(const list& origArgs) } } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -612,9 +612,9 @@ Parser::removeApplication(const list& args) _admin->removeApplication(name); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -640,9 +640,9 @@ Parser::describeApplication(const list& args) out << nl; outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -756,9 +756,9 @@ Parser::diffApplication(const list& origArgs) out << nl; outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -826,9 +826,9 @@ Parser::updateApplication(const list& origArgs) { error("registry doesn't support updates without restart"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -867,9 +867,9 @@ Parser::patchApplication(const list& origArgs) string name = *p++; _admin->patchApplication(name, opts.isSet("force")); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -889,9 +889,9 @@ Parser::listAllApplications(const list& args) copy(names.begin(), names.end(), ostream_iterator(os,"\n")); outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -943,9 +943,9 @@ Parser::describeServerTemplate(const list& args) } outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -980,9 +980,9 @@ Parser::instantiateServerTemplate(const list& args) desc.parameterValues = vars; _admin->instantiateServer(application, node, desc); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1026,9 +1026,9 @@ Parser::describeServiceTemplate(const list& args) } outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1058,9 +1058,9 @@ Parser::describeNode(const list& args) out << nl; outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1084,9 +1084,9 @@ Parser::pingNode(const list& args) consoleOut << "node is down" << endl; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1104,9 +1104,9 @@ Parser::printLoadNode(const list& args) LoadInfo load = _admin->getNodeLoad(args.front()); consoleOut << "load average (1/5/15): " << load.avg1 << " / " << load.avg5 << " / " << load.avg15 << endl; } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1175,9 +1175,9 @@ Parser::printNodeProcessorSockets(const list& args) consoleOut << os.str() << flush; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1194,9 +1194,9 @@ Parser::shutdownNode(const list& args) { _admin->shutdownNode(args.front()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1216,9 +1216,9 @@ Parser::listAllNodes(const list& args) copy(names.begin(), names.end(), ostream_iterator(os,"\n")); consoleOut << os.str(); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1243,9 +1243,9 @@ Parser::describeRegistry(const list& args) out << nl; outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1269,9 +1269,9 @@ Parser::pingRegistry(const list& args) consoleOut << "registry is down" << endl; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1295,9 +1295,9 @@ Parser::shutdownRegistry(const list& args) _admin->shutdownRegistry(args.front()); } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1317,9 +1317,9 @@ Parser::listAllRegistries(const list& args) copy(names.begin(), names.end(), ostream_iterator(os,"\n")); consoleOut << os.str(); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1343,9 +1343,9 @@ Parser::removeServer(const list& args) update.nodes.push_back(nodeUpdate); _admin->updateApplication(update); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1366,9 +1366,9 @@ Parser::startServer(const list& args) { error("the server didn't start successfully:\n" + ex.reason); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1389,9 +1389,9 @@ Parser::stopServer(const list& args) { error("the server didn't stop successfully:\n" + ex.reason); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1428,9 +1428,9 @@ Parser::patchServer(const list& origArgs) { _admin->patchServer(args.front(), opts.isSet("force")); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1449,9 +1449,9 @@ Parser::signalServer(const list& args) string server = *p++; _admin->sendSignal(server, *p); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1482,9 +1482,9 @@ Parser::writeMessage(const list& args, int fd) { error("the server's Admin object does not provide a 'Process' facet"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1514,9 +1514,9 @@ Parser::describeServer(const list& args) out << nl; outputString(os.str()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1576,9 +1576,9 @@ Parser::stateServer(const list& args) assert(false); } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1603,9 +1603,9 @@ Parser::pidServer(const list& args) error("server is not running"); } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1649,9 +1649,9 @@ Parser::propertiesServer(const list& args, bool single) { error("the server's Admin object does not provide a 'Properties' facet"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1675,9 +1675,9 @@ Parser::enableServer(const list& args, bool enable) { _admin->enableServer(args.front(), enable); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1697,9 +1697,9 @@ Parser::listAllServers(const list& args) copy(ids.begin(), ids.end(), ostream_iterator(os,"\n")); consoleOut << os.str(); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1736,9 +1736,9 @@ Parser::startService(const list& args) { error("the server's Admin object does not provide a 'IceBox.ServiceManager' facet"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1775,9 +1775,9 @@ Parser::stopService(const list& args) { error("the server's Admin object does not provide a 'IceBox.ServiceManager' facet"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1823,9 +1823,9 @@ Parser::describeService(const list& args) return; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1910,9 +1910,9 @@ Parser::propertiesService(const list& args, bool single) { error("the server's Admin object does not provide an 'IceBox.Service." + service + ".Properties' facet"); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1943,9 +1943,9 @@ Parser::listServices(const list& args) } } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1977,9 +1977,9 @@ Parser::endpointsAdapter(const list& args) } } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -1996,9 +1996,9 @@ Parser::removeAdapter(const list& args) { _admin->removeAdapter(*args.begin()); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2018,9 +2018,9 @@ Parser::listAllAdapters(const list& args) copy(ids.begin(), ids.end(), ostream_iterator(os,"\n")); consoleOut << os.str(); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2049,9 +2049,9 @@ Parser::addObject(const list& args) _admin->addObject(_communicator->stringToProxy(proxy)); } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2068,9 +2068,9 @@ Parser::removeObject(const list& args) { _admin->removeObject(Ice::stringToIdentity((*(args.begin())))); } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2091,9 +2091,9 @@ Parser::findObject(const list& args) consoleOut << _communicator->proxyToString(p->proxy) << endl; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2135,9 +2135,9 @@ Parser::describeObject(const list& args) } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2167,9 +2167,9 @@ Parser::listObject(const list& args) consoleOut << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl; } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2264,9 +2264,9 @@ Parser::show(const string& reader, const list& origArgs) showFile(id, reader, filename, head, tail, follow, lineCount); } } - catch(const Ice::Exception& ex) + catch(const Ice::Exception&) { - exception(ex); + exception(current_exception()); } } @@ -2858,11 +2858,11 @@ Parser::parse(const std::string& commands, bool debug) } void -Parser::exception(const Ice::Exception& pex) +Parser::exception(std::exception_ptr pex) { try { - pex.ice_throw(); + rethrow_exception(pex); } catch(const ApplicationNotExistException& ex) { diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h index e23449b785e..1c4e0d9a26f 100644 --- a/cpp/src/IceGrid/Parser.h +++ b/cpp/src/IceGrid/Parser.h @@ -140,7 +140,7 @@ class Parser private: - void exception(const Ice::Exception&); + void exception(std::exception_ptr); void showFile(const std::string&, const std::string&, const std::string&, bool, bool, bool, int); void showLog(const std::string&, const std::string&, bool, bool, int); diff --git a/cpp/src/IceGrid/ReapThread.h b/cpp/src/IceGrid/ReapThread.h index 99afaa8f56f..1eab7b65f93 100644 --- a/cpp/src/IceGrid/ReapThread.h +++ b/cpp/src/IceGrid/ReapThread.h @@ -61,7 +61,7 @@ class SessionReapable : public Reapable catch(const Ice::ObjectNotExistException&) { } - catch(const Ice::LocalException& ex) + catch (const std::exception& ex) { Ice::Warning out(_logger); out << "unexpected exception while reaping session:\n" << ex; diff --git a/cpp/src/IceIAP/Transceiver.h b/cpp/src/IceIAP/Transceiver.h index 32e8da85300..a868fe92ddd 100644 --- a/cpp/src/IceIAP/Transceiver.h +++ b/cpp/src/IceIAP/Transceiver.h @@ -41,7 +41,7 @@ class iAPTransceiver final : public IceInternal::Transceiver, public IceInternal IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close() final; IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; diff --git a/cpp/src/IceLocatorDiscovery/PluginI.cpp b/cpp/src/IceLocatorDiscovery/PluginI.cpp index b711cae8d3d..d0ac6f05e84 100644 --- a/cpp/src/IceLocatorDiscovery/PluginI.cpp +++ b/cpp/src/IceLocatorDiscovery/PluginI.cpp @@ -43,7 +43,7 @@ class Request : public std::enable_shared_from_this void invoke(const Ice::LocatorPrxPtr&); void response(bool, const pair&); - void exception(const Ice::Exception&); + void exception(std::exception_ptr); protected: @@ -78,7 +78,7 @@ class LocatorI : public Ice::BlobjectArrayAsync, vector getLocators(const string&, const chrono::milliseconds&); - void exception(const Ice::LocalException&); + void exception(std::exception_ptr); private: @@ -341,21 +341,14 @@ Request::invoke(const Ice::LocatorPrxPtr& l) }, [self](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - self->exception(ex); - } + self->exception(e); }, nullptr, _context); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - exception(ex); + exception(current_exception()); } } else @@ -372,56 +365,35 @@ Request::response(bool ok, const pair& outPa } void -Request::exception(const Ice::Exception& ex) +Request::exception(std::exception_ptr ex) { try { - ex.ice_throw(); + rethrow_exception(ex); } catch(const Ice::RequestFailedException&) { - _amdCB.second(current_exception()); + _amdCB.second(ex); } catch(const Ice::UnknownException&) { - _amdCB.second(current_exception()); + _amdCB.second(ex); } catch(const Ice::NoEndpointException&) { - try - { - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - catch(...) - { - _amdCB.second(current_exception()); - } + _amdCB.second(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); } catch(const Ice::CommunicatorDestroyedException&) { - try - { - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - catch(...) - { - _amdCB.second(current_exception()); - } + _amdCB.second(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); } catch(const Ice::ObjectAdapterDeactivatedException&) { - try - { - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - catch(...) - { - _amdCB.second(current_exception()); - } + _amdCB.second(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); } - catch(const Ice::Exception&) + catch (...) { - _exception = current_exception(); + _exception = ex; _locator->invoke(_locatorPrx, shared_from_this()); // Retry with new locator proxy } } @@ -729,14 +701,7 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) auto self = shared_from_this(); l->first->findLocatorAsync(_instanceName, l->second, nullptr, [self](exception_ptr ex) { - try - { - rethrow_exception(ex); - } - catch(const Ice::LocalException& e) - { - self->exception(e); - } + self->exception(ex); }); } _timer->schedule(shared_from_this(), _timeout); @@ -767,7 +732,7 @@ LocatorI::invoke(const Ice::LocatorPrxPtr& locator, const RequestPtr& request) } void -LocatorI::exception(const Ice::LocalException& ex) +LocatorI::exception(std::exception_ptr ex) { lock_guard lock(_mutex); if(++_failureCount == _lookups.size() && _pending) @@ -781,9 +746,16 @@ LocatorI::exception(const Ice::LocalException& ex) if(_warnOnce) { - Ice::Warning warn(_lookup->ice_getCommunicator()->getLogger()); - warn << "failed to lookup locator with lookup proxy `" << _lookup << "':\n" << ex; - _warnOnce = false; + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + Ice::Warning warn(_lookup->ice_getCommunicator()->getLogger()); + warn << "failed to lookup locator with lookup proxy `" << _lookup << "':\n" << e; + _warnOnce = false; + } } if(_traceLevel > 0) @@ -794,7 +766,15 @@ LocatorI::exception(const Ice::LocalException& ex) { out << "\ninstance name = " << _instanceName; } - out << "\n" << ex; + + try + { + rethrow_exception(ex); + } + catch (const std::exception& e) + { + out << "\n" << e; + } } if(_pendingRequests.empty()) @@ -843,14 +823,7 @@ LocatorI::runTimerTask() auto self = shared_from_this(); l->first->findLocatorAsync(_instanceName, l->second, nullptr, [self](exception_ptr ex) { - try - { - rethrow_exception(ex); - } - catch(const Ice::LocalException& e) - { - self->exception(e); - } + self->exception(ex); }); } _timer->schedule(shared_from_this(), _timeout); diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp index dccb640e2b1..0e09075161a 100644 --- a/cpp/src/IceSSL/EndpointI.cpp +++ b/cpp/src/IceSSL/EndpointI.cpp @@ -169,7 +169,7 @@ IceSSL::EndpointI::connectors_async(Ice::EndpointSelectionType selType, _callback->connectors(connectors); } - virtual void exception(const Ice::LocalException& ex) + virtual void exception(std::exception_ptr ex) { _callback->exception(ex); } diff --git a/cpp/src/IceSSL/OpenSSLTransceiverI.cpp b/cpp/src/IceSSL/OpenSSLTransceiverI.cpp index dbf1d3e3d68..958e9b4feab 100644 --- a/cpp/src/IceSSL/OpenSSLTransceiverI.cpp +++ b/cpp/src/IceSSL/OpenSSLTransceiverI.cpp @@ -479,7 +479,7 @@ OpenSSL::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal:: } IceInternal::SocketOperation -OpenSSL::TransceiverI::closing(bool initiator, const Ice::LocalException&) +OpenSSL::TransceiverI::closing(bool initiator, exception_ptr) { // If we are initiating the connection closure, wait for the peer // to close the TCP/IP connection. Otherwise, close immediately. diff --git a/cpp/src/IceSSL/OpenSSLTransceiverI.h b/cpp/src/IceSSL/OpenSSLTransceiverI.h index 0fabaa8ff0f..13614a501a4 100644 --- a/cpp/src/IceSSL/OpenSSLTransceiverI.h +++ b/cpp/src/IceSSL/OpenSSLTransceiverI.h @@ -34,7 +34,7 @@ class TransceiverI final : public IceInternal::Transceiver IceInternal::NativeInfoPtr getNativeInfo() final; IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close() final; IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; diff --git a/cpp/src/IceSSL/SChannelTransceiverI.cpp b/cpp/src/IceSSL/SChannelTransceiverI.cpp index 2c10fa5f35f..875a943a7a0 100644 --- a/cpp/src/IceSSL/SChannelTransceiverI.cpp +++ b/cpp/src/IceSSL/SChannelTransceiverI.cpp @@ -907,7 +907,7 @@ SChannel::TransceiverI::initialize(IceInternal::Buffer& readBuffer, IceInternal: } IceInternal::SocketOperation -SChannel::TransceiverI::closing(bool initiator, const Ice::LocalException&) +SChannel::TransceiverI::closing(bool initiator, exception_ptr) { // If we are initiating the connection closure, wait for the peer // to close the TCP/IP connection. Otherwise, close immediately. diff --git a/cpp/src/IceSSL/SChannelTransceiverI.h b/cpp/src/IceSSL/SChannelTransceiverI.h index 5c5cfbedfb1..57a0391bb37 100644 --- a/cpp/src/IceSSL/SChannelTransceiverI.h +++ b/cpp/src/IceSSL/SChannelTransceiverI.h @@ -47,7 +47,7 @@ class TransceiverI final : public IceInternal::Transceiver IceInternal::NativeInfoPtr getNativeInfo() final; IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close(); IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; diff --git a/cpp/src/IceSSL/SecureTransportTransceiverI.cpp b/cpp/src/IceSSL/SecureTransportTransceiverI.cpp index cce221ab2db..f503ed18702 100644 --- a/cpp/src/IceSSL/SecureTransportTransceiverI.cpp +++ b/cpp/src/IceSSL/SecureTransportTransceiverI.cpp @@ -413,7 +413,7 @@ IceSSL::SecureTransport::TransceiverI::initialize(IceInternal::Buffer& readBuffe } IceInternal::SocketOperation -IceSSL::SecureTransport::TransceiverI::closing(bool initiator, const Ice::LocalException&) +IceSSL::SecureTransport::TransceiverI::closing(bool initiator, exception_ptr) { // If we are initiating the connection closure, wait for the peer // to close the TCP/IP connection. Otherwise, close immediately. diff --git a/cpp/src/IceSSL/SecureTransportTransceiverI.h b/cpp/src/IceSSL/SecureTransportTransceiverI.h index 75c9218f977..703335bb9b9 100644 --- a/cpp/src/IceSSL/SecureTransportTransceiverI.h +++ b/cpp/src/IceSSL/SecureTransportTransceiverI.h @@ -35,7 +35,7 @@ class TransceiverI final : public IceInternal::Transceiver IceInternal::NativeInfoPtr getNativeInfo() final; IceInternal::SocketOperation initialize(IceInternal::Buffer&, IceInternal::Buffer&) final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close() final; IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; diff --git a/cpp/test/Glacier2/sessionHelper/Client.cpp b/cpp/test/Glacier2/sessionHelper/Client.cpp index 1777d7bbe99..866911ef068 100644 --- a/cpp/test/Glacier2/sessionHelper/Client.cpp +++ b/cpp/test/Glacier2/sessionHelper/Client.cpp @@ -109,7 +109,7 @@ class SuccessSessionCallback final : public Glacier2::SessionCallback } void - connectFailed(const shared_ptr&, const Ice::Exception&) override + connectFailed(const shared_ptr&, std::exception_ptr) override { test(false); } @@ -138,11 +138,11 @@ class AfterShutdownSessionCallback final : public Glacier2::SessionCallback } void - connectFailed(const shared_ptr&, const Ice::Exception& ex) override + connectFailed(const shared_ptr&, std::exception_ptr ex) override { try { - ex.ice_throw(); + rethrow_exception(ex); } catch(const Ice::ConnectFailedException&) { @@ -179,11 +179,11 @@ class FailSessionCallback final : public Glacier2::SessionCallback } void - connectFailed(const shared_ptr&, const Ice::Exception& ex) override + connectFailed(const shared_ptr&, std::exception_ptr ex) override { try { - ex.ice_throw(); + rethrow_exception(ex); } catch(const Glacier2::PermissionDeniedException&) { @@ -220,11 +220,11 @@ class InterruptConnectCallback final : public Glacier2::SessionCallback } void - connectFailed(const shared_ptr&, const Ice::Exception& ex) override + connectFailed(const shared_ptr&, std::exception_ptr ex) override { try { - ex.ice_throw(); + rethrow_exception(ex); } catch(const Ice::CommunicatorDestroyedException&) { diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index 2bd5e745aa8..3ff4605d281 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -158,7 +158,7 @@ EndpointI::connectors_async(Ice::EndpointSelectionType selType, const IceInterna } void - exception(const Ice::LocalException& ex) + exception(std::exception_ptr ex) { _callback->exception(ex); } @@ -173,9 +173,9 @@ EndpointI::connectors_async(Ice::EndpointSelectionType selType, const IceInterna _configuration->checkConnectorsException(); _endpoint->connectors_async(selType, make_shared(cb)); } - catch(const Ice::LocalException& ex) + catch(const Ice::LocalException&) { - cb->exception(ex); + cb->exception(current_exception()); } } diff --git a/cpp/test/Ice/background/Transceiver.cpp b/cpp/test/Ice/background/Transceiver.cpp index 8bbd15f8a93..3e92ccac4d7 100644 --- a/cpp/test/Ice/background/Transceiver.cpp +++ b/cpp/test/Ice/background/Transceiver.cpp @@ -55,7 +55,7 @@ Transceiver::initialize(IceInternal::Buffer& readBuffer, IceInternal::Buffer& wr } IceInternal::SocketOperation -Transceiver::closing(bool initiator, const Ice::LocalException& ex) +Transceiver::closing(bool initiator, std::exception_ptr ex) { return _transceiver->closing(initiator, ex); } diff --git a/cpp/test/Ice/background/Transceiver.h b/cpp/test/Ice/background/Transceiver.h index 7b79da3feeb..617b2a77f4c 100644 --- a/cpp/test/Ice/background/Transceiver.h +++ b/cpp/test/Ice/background/Transceiver.h @@ -16,7 +16,7 @@ class Transceiver final : public IceInternal::Transceiver Transceiver(const IceInternal::TransceiverPtr&); IceInternal::NativeInfoPtr getNativeInfo() final; - IceInternal::SocketOperation closing(bool, const Ice::LocalException&) final; + IceInternal::SocketOperation closing(bool, std::exception_ptr) final; void close(); IceInternal::SocketOperation write(IceInternal::Buffer&) final; IceInternal::SocketOperation read(IceInternal::Buffer&) final; diff --git a/cpp/test/Ice/interceptor/AMDInterceptorI.cpp b/cpp/test/Ice/interceptor/AMDInterceptorI.cpp index ec97612da6f..a4c09deffa9 100644 --- a/cpp/test/Ice/interceptor/AMDInterceptorI.cpp +++ b/cpp/test/Ice/interceptor/AMDInterceptorI.cpp @@ -72,18 +72,7 @@ AMDInterceptorI::dispatch(Ice::Request& request) } _lastStatus = _servant->ice_dispatch(request, []() { return true; }, [this](exception_ptr ex) { - try - { - rethrow_exception(ex); - } - catch(const IceUtil::Exception& e) - { - setException(e); - } - catch(...) - { - test(false); - } + setException(ex); return true; }); @@ -108,17 +97,17 @@ AMDInterceptorI::dispatch(Ice::Request& request) } void -AMDInterceptorI::setException(const IceUtil::Exception& e) +AMDInterceptorI::setException(std::exception_ptr e) { IceUtil::Mutex::Lock lock(_mutex); - _exception = e.ice_clone(); + _exception = e; } -IceUtil::Exception* +std::exception_ptr AMDInterceptorI::getException() const { IceUtil::Mutex::Lock lock(_mutex); - return _exception.get(); + return _exception; } void @@ -126,5 +115,5 @@ AMDInterceptorI::clear() { InterceptorI::clear(); IceUtil::Mutex::Lock lock(_mutex); - _exception.reset(); + _exception = nullptr; } diff --git a/cpp/test/Ice/interceptor/AMDInterceptorI.h b/cpp/test/Ice/interceptor/AMDInterceptorI.h index 106b89488a4..8179f5af781 100644 --- a/cpp/test/Ice/interceptor/AMDInterceptorI.h +++ b/cpp/test/Ice/interceptor/AMDInterceptorI.h @@ -18,12 +18,12 @@ class AMDInterceptorI : public InterceptorI virtual void clear(); - IceUtil::Exception* getException() const; - void setException(const IceUtil::Exception&); + std::exception_ptr getException() const; + void setException(std::exception_ptr); private: - std::unique_ptr _exception; + std::exception_ptr _exception; IceUtil::Mutex _mutex; }; diff --git a/cpp/test/Ice/interceptor/Client.cpp b/cpp/test/Ice/interceptor/Client.cpp index c695de60977..21e3ee083a2 100644 --- a/cpp/test/Ice/interceptor/Client.cpp +++ b/cpp/test/Ice/interceptor/Client.cpp @@ -227,7 +227,18 @@ Client::runAmdTest(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& in test(interceptor->getLastOperation() == "amdNotExistAdd"); test(!interceptor->getLastStatus()); - test(dynamic_cast(interceptor->getException()) != 0); + try + { + rethrow_exception(interceptor->getException()); + } + catch (const Ice::ObjectNotExistException&) + { + // ok + } + catch (...) + { + test(false); + } cout << "ok" << endl; cout << "testing system exception... " << flush; @@ -245,9 +256,23 @@ Client::runAmdTest(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& in { test(prx->ice_isCollocationOptimized()); } + test(interceptor->getLastOperation() == "amdBadSystemAdd"); test(!interceptor->getLastStatus()); - test(dynamic_cast(interceptor->getException()) != 0); + + try + { + rethrow_exception(interceptor->getException()); + } + catch (const MySystemException&) + { + // ok + } + catch (...) + { + test(false); + } + cout << "ok" << endl; cout << "testing exceptions raised by the interceptor... " << flush; diff --git a/cpp/test/Ice/interceptor/MyObjectI.cpp b/cpp/test/Ice/interceptor/MyObjectI.cpp index 4a954d0d064..d8ff3b2d1af 100644 --- a/cpp/test/Ice/interceptor/MyObjectI.cpp +++ b/cpp/test/Ice/interceptor/MyObjectI.cpp @@ -121,14 +121,7 @@ MyObjectI::amdAddWithRetryAsync(int x, if(p == current.ctx.end() || p->second != "no") { - try - { - throw MyRetryException(); - } - catch(...) - { - error(std::current_exception()); - } + error(make_exception_ptr(MyRetryException())); } } @@ -143,14 +136,7 @@ MyObjectI::amdBadAddAsync(int, [error]() { this_thread::sleep_for(chrono::milliseconds(10)); - try - { - throw Test::InvalidInputException(); - } - catch(...) - { - error(std::current_exception()); - } + error(make_exception_ptr(Test::InvalidInputException())); }); t.detach(); } @@ -166,14 +152,7 @@ MyObjectI::amdNotExistAddAsync(int, [error]() { this_thread::sleep_for(chrono::milliseconds(10)); - try - { - throw Ice::ObjectNotExistException(__FILE__, __LINE__); - } - catch(...) - { - error(std::current_exception()); - } + error(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); }); t.detach(); } @@ -189,14 +168,7 @@ MyObjectI::amdBadSystemAddAsync(int, [error]() { this_thread::sleep_for(chrono::milliseconds(10)); - try - { - throw MySystemException(__FILE__, __LINE__); - } - catch(...) - { - error(std::current_exception()); - } + error(make_exception_ptr(MySystemException(__FILE__, __LINE__))); }); t.detach(); } diff --git a/cpp/test/Ice/metrics/AllTests.cpp b/cpp/test/Ice/metrics/AllTests.cpp index 620f6c30211..97d830fa756 100644 --- a/cpp/test/Ice/metrics/AllTests.cpp +++ b/cpp/test/Ice/metrics/AllTests.cpp @@ -23,7 +23,7 @@ class CallbackBase : public IceUtil::Shared, protected IceUtil::Monitorresponse(); }, - [cb](exception_ptr e) + [cb](exception_ptr) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - test(false); - } - catch(...) - { - test(false); - } + test(false); }); cb->waitForResponse(); @@ -1169,18 +1156,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }); cb->waitForResponse(); @@ -1211,18 +1187,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }); cb->waitForResponse(); @@ -1253,18 +1218,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }); cb->waitForResponse(); @@ -1295,18 +1249,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }); cb->waitForResponse(); @@ -1339,18 +1282,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }); cb->waitForResponse(); } @@ -1450,18 +1382,7 @@ allTests(Test::TestHelper* helper, const CommunicatorObserverIPtr& obsv) }, [cb](exception_ptr e) { - try - { - rethrow_exception(e); - } - catch(const Ice::Exception& ex) - { - cb->exception(ex); - } - catch(...) - { - test(false); - } + cb->exception(e); }, [&](bool) { sent.set_value(); }); sent.get_future().get(); diff --git a/cpp/test/Ice/services/AllTests.cpp b/cpp/test/Ice/services/AllTests.cpp index cbc106e4bc5..682fb64bb43 100644 --- a/cpp/test/Ice/services/AllTests.cpp +++ b/cpp/test/Ice/services/AllTests.cpp @@ -42,7 +42,7 @@ class SessionCallbackI : public Glacier2::SessionCallback } virtual void - connectFailed(const Glacier2::SessionHelperPtr&, const Ice::Exception&) + connectFailed(const Glacier2::SessionHelperPtr&, std::exception_ptr) { }