diff options
author | Marc Laukien <marc@zeroc.com> | 2002-12-07 22:17:44 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-12-07 22:17:44 +0000 |
commit | bec87e9b6a7edcbbfce5fadb520c41816143a8be (patch) | |
tree | d428b8bf9306090d456b198c87d34e0dd048a5cb /cpp | |
parent | AMD exception cleanup (diff) | |
download | ice-bec87e9b6a7edcbbfce5fadb520c41816143a8be.tar.bz2 ice-bec87e9b6a7edcbbfce5fadb520c41816143a8be.tar.xz ice-bec87e9b6a7edcbbfce5fadb520c41816143a8be.zip |
more AMD exception fixes
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/IncomingAsync.h | 7 | ||||
-rw-r--r-- | cpp/src/Ice/IncomingAsync.cpp | 144 | ||||
-rw-r--r-- | cpp/src/Ice/Object.cpp | 17 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 33 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/AllTests.cpp | 66 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/Test.ice | 1 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/TestAMD.ice | 1 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/TestAMDI.cpp | 18 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/TestAMDI.h | 2 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/TestI.cpp | 6 | ||||
-rw-r--r-- | cpp/test/Ice/exceptions/TestI.h | 1 |
11 files changed, 154 insertions, 142 deletions
diff --git a/cpp/include/Ice/IncomingAsync.h b/cpp/include/Ice/IncomingAsync.h index 3ca0b7b2f48..aed7ed4240a 100644 --- a/cpp/include/Ice/IncomingAsync.h +++ b/cpp/include/Ice/IncomingAsync.h @@ -35,12 +35,13 @@ class ICE_API IncomingAsync : virtual public ::IceUtil::Shared public: IncomingAsync(Incoming&); // Adopts the Incoming argument. It must not be used afterwards. - void __restore(Incoming&); // Restores the Incoming from the IncomingAsync. protected: void __response(bool); void __exception(const ::Ice::Exception&); + void __exception(const ::std::exception&); + void __exception(); void __fatal(const ::Ice::LocalException&); BasicStream* __is(); @@ -79,6 +80,8 @@ public: virtual void ice_response(bool, const ::std::vector< ::Ice::Byte>&) = 0; virtual void ice_exception(const ::IceUtil::Exception&) = 0; + virtual void ice_exception(const ::std::exception&) = 0; + virtual void ice_exception() = 0; }; } @@ -97,6 +100,8 @@ public: virtual void ice_response(bool, const ::std::vector< ::Ice::Byte>&); virtual void ice_exception(const ::IceUtil::Exception&); + virtual void ice_exception(const ::std::exception&); + virtual void ice_exception(); }; } diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 3ae55e0d4d4..a6e1559c5ee 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -82,6 +82,21 @@ IceInternal::IncomingAsync::__exception(const Exception& exc) { finishInvoke(); + if(ex.id.name.empty()) + { + ex.id = _current.id; + } + + if(ex.facet.empty() && !_current.facet.empty()) + { + ex.facet = _current.facet; + } + + if(ex.operation.empty() && !_current.operation.empty()) + { + ex.operation = _current.operation; + } + if(_connection) // Response expected? { _os.endWriteEncaps(); @@ -102,64 +117,12 @@ IceInternal::IncomingAsync::__exception(const Exception& exc) { assert(false); } - - // - // Write the data from the exception if set so that a - // RequestFailedException can override the information - // from _current. - // - if(!ex.id.name.empty()) - { - ex.id.__write(&_os); - } - else - { - _current.id.__write(&_os); - } - - if(!ex.facet.empty()) - { - _os.write(ex.facet); - } - else - { - _os.write(_current.facet); - } - - if(ex.operation.empty()) - { - _os.write(ex.operation); - } - else - { - _os.write(_current.operation); - } + ex.id.__write(&_os); + _os.write(ex.facet); + _os.write(ex.operation); _connection->sendResponse(&_os, _compress); } - -/* - if(_instance->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 1) - { - if(ex.id.name.empty()) - { - ex.id = _current.id; - } - - if(ex.facet.empty() && !_current.facet.empty()) - { - ex.facet = _current.facet; - } - - if(ex.operation.empty() && !_current.operation.empty()) - { - ex.operation = _current.operation; - } - - Warning out(_instance->logger()); - out << "dispatch exception:\n" << ex; - } -*/ } catch(const LocalException& ex) { @@ -176,14 +139,6 @@ IceInternal::IncomingAsync::__exception(const Exception& exc) _connection->sendResponse(&_os, _compress); } -/* - if(_instance->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - ostringstream str; - str << ex; - warning("dispatch exception: unknown local exception:", str.str()); - } -*/ } catch(const UserException& ex) { @@ -200,15 +155,6 @@ IceInternal::IncomingAsync::__exception(const Exception& exc) _connection->sendResponse(&_os, _compress); } - -/* - if(_instance->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - ostringstream str; - str << ex; - warning("dispatch exception: unknown user exception:", str.str()); - } -*/ } catch(const Exception& ex) { @@ -225,15 +171,39 @@ IceInternal::IncomingAsync::__exception(const Exception& exc) _connection->sendResponse(&_os, _compress); } + } +} -/* - if(_instance->properties()->getPropertyAsIntWithDefault("Ice.Warn.Dispatch", 1) > 0) - { - ostringstream str; - str << ex; - warning("dispatch exception: unknown exception:", str.str()); - } -*/ +void +IceInternal::IncomingAsync::__exception(const std::exception& ex) +{ + finishInvoke(); + + if(_connection) // Response expected? + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + ostringstream str; + str << "std::exception: " << ex.what(); + _os.write(str.str()); + + _connection->sendResponse(&_os, _compress); + } +} + +void +IceInternal::IncomingAsync::__exception() +{ + if(_connection) // Response expected? + { + _os.endWriteEncaps(); + _os.b.resize(headerSize + 4); // Dispatch status position. + _os.write(static_cast<Byte>(DispatchUnknownException)); + string reason = "unknown c++ exception"; + _os.write(reason); + + _connection->sendResponse(&_os, _compress); } } @@ -293,7 +263,7 @@ IceAsync::Ice::AMD_Object_ice_invoke::ice_response(bool ok, const ::std::vector< } catch(const LocalException& ex) { - ice_exception(ex); + __exception(ex); return; } @@ -305,3 +275,15 @@ IceAsync::Ice::AMD_Object_ice_invoke::ice_exception(const Exception& ex) { __exception(ex); } + +void +IceAsync::Ice::AMD_Object_ice_invoke::ice_exception(const std::exception& ex) +{ + __exception(ex); +} + +void +IceAsync::Ice::AMD_Object_ice_invoke::ice_exception() +{ + __exception(); +} diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 14a7e935296..ac3448c8b7a 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -437,6 +437,21 @@ Ice::BlobjectAsync::__dispatch(Incoming& in, const Current& current) Int sz = in.is()->getReadEncapsSize(); in.is()->readBlob(inParams, sz); AMD_Object_ice_invokePtr cb = new ::IceAsync::Ice::AMD_Object_ice_invoke(in); - ice_invoke_async(cb, inParams, current); + try + { + ice_invoke_async(cb, inParams, current); + } + catch(const Exception& ex) + { + cb->ice_exception(ex); + } + catch(const ::std::exception& ex) + { + cb->ice_exception(ex); + } + catch(...) + { + cb->ice_exception(); + } return ::IceInternal::DispatchOK; } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 24beb414196..c7ecc516a3f 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -2528,7 +2528,22 @@ Slice::Gen::ObjectVisitor::visitOperation(const OperationPtr& p) writeUnmarshalCode(C, inParams, 0); C << nl << classScopedAMD << '_' << name << "Ptr __cb = new ::IceAsync" << classScopedAMD << '_' << name << "(__in);"; + C << nl << "try"; + C << sb; C << nl << name << "_async" << argsAMD << ';'; + C << eb; + C << nl << "catch(const ::Ice::Exception& __ex)"; + C << sb; + C << nl << "__cb->ice_exception(__ex);"; + C << eb; + C << nl << "catch(const ::std::exception& __ex)"; + C << sb; + C << nl << "__cb->ice_exception(__ex);"; + C << eb; + C << nl << "catch(...)"; + C << sb; + C << nl << "__cb->ice_exception();"; + C << eb; C << nl << "return ::IceInternal::DispatchOK;"; } C << eb; @@ -3384,6 +3399,8 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p) H << sp; H << nl << "virtual void ice_response(" << params << ") = 0;"; H << nl << "virtual void ice_exception(const ::Ice::Exception&) = 0;"; + H << nl << "virtual void ice_exception(const ::std::exception&) = 0;"; + H << nl << "virtual void ice_exception() = 0;"; H << eb << ';'; H << sp << nl << "typedef ::IceUtil::Handle< " << classScopedAMD << '_' << name << "> " << classNameAMD << '_' << name << "Ptr;"; @@ -3515,6 +3532,8 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) H << sp; H << nl << "virtual void ice_response(" << params << ");"; H << nl << "virtual void ice_exception(const ::Ice::Exception&);"; + H << nl << "virtual void ice_exception(const ::std::exception&);"; + H << nl << "virtual void ice_exception();"; H << eb << ';'; C << sp << nl << "::IceAsync" << classScopedAMD << '_' << name << "::" << classNameAMD << '_' << name @@ -3537,7 +3556,7 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) C << eb; C << nl << "catch(const ::Ice::Exception& __ex)"; C << sb; - C << nl << "ice_exception(__ex);"; + C << nl << "__exception(__ex);"; C << nl << "return;"; C << eb; } @@ -3572,5 +3591,17 @@ Slice::Gen::AsyncImplVisitor::visitOperation(const OperationPtr& p) C << eb; } C << eb; + + C << sp << nl << "void" << nl << "::IceAsync" << classScopedAMD << '_' << name + << "::ice_exception(const ::std::exception& ex)"; + C << sb; + C << nl << "__exception(ex);"; + C << eb; + + C << sp << nl << "void" << nl << "::IceAsync" << classScopedAMD << '_' << name + << "::ice_exception()"; + C << sb; + C << nl << "__exception();"; + C << eb; } } diff --git a/cpp/test/Ice/exceptions/AllTests.cpp b/cpp/test/Ice/exceptions/AllTests.cpp index b8bbad1b017..0c800ad3fe1 100644 --- a/cpp/test/Ice/exceptions/AllTests.cpp +++ b/cpp/test/Ice/exceptions/AllTests.cpp @@ -1216,34 +1216,31 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) cout << "ok" << endl; - if(thrower->supportsNonIceExceptions()) + cout << "catching unknown non-Ice exception... " << flush; + + try { - cout << "catching unknown non-Ice exception... " << flush; - - try - { - thrower->throwNonIceException(); - test(false); - } - catch(const Ice::UnknownException&) - { - // - // We get the an unknown exception without collocation - // optimization. - // - assert(!collocated); - } - catch(...) - { - // - // We get the original exception with collocation - // optimization. - // - assert(collocated); - } - - cout << "ok" << endl; + thrower->throwNonIceException(); + test(false); } + catch(const Ice::UnknownException&) + { + // + // We get the an unknown exception without collocation + // optimization. + // + assert(!collocated); + } + catch(...) + { + // + // We get the original exception with collocation + // optimization. + // + assert(collocated); + } + + cout << "ok" << endl; if(!collocated) // If the server is collocated, exception factories are not needed. { @@ -1415,16 +1412,13 @@ allTests(const Ice::CommunicatorPtr& communicator, bool collocated) cout << "ok" << endl; - if(thrower->supportsNonIceExceptions()) - { - cout << "catching unknown non-Ice exception with AMI... " << flush; - - AMI_Thrower_throwNonIceExceptionIPtr cb = new AMI_Thrower_throwNonIceExceptionI; - thrower->throwNonIceException_async(cb); - test(cb->check()); - - cout << "ok" << endl; - } + cout << "catching unknown non-Ice exception with AMI... " << flush; + + AMI_Thrower_throwNonIceExceptionIPtr cb = new AMI_Thrower_throwNonIceExceptionI; + thrower->throwNonIceException_async(cb); + test(cb->check()); + + cout << "ok" << endl; communicator->removeUserExceptionFactory("::A"); communicator->removeUserExceptionFactory("::B"); diff --git a/cpp/test/Ice/exceptions/Test.ice b/cpp/test/Ice/exceptions/Test.ice index ee59247da04..c447b24aaf3 100644 --- a/cpp/test/Ice/exceptions/Test.ice +++ b/cpp/test/Ice/exceptions/Test.ice @@ -45,7 +45,6 @@ exception D { void shutdown(); bool supportsUndeclaredExceptions(); - bool supportsNonIceExceptions(); void throwAasA(int a) throws A; void throwAorDasAorD(int a) throws A, D; diff --git a/cpp/test/Ice/exceptions/TestAMD.ice b/cpp/test/Ice/exceptions/TestAMD.ice index 709469ae075..25933cff713 100644 --- a/cpp/test/Ice/exceptions/TestAMD.ice +++ b/cpp/test/Ice/exceptions/TestAMD.ice @@ -41,7 +41,6 @@ exception D { void shutdown(); bool supportsUndeclaredExceptions(); - bool supportsNonIceExceptions(); void throwAasA(int a) throws A; void throwAorDasAorD(int a) throws A, D; diff --git a/cpp/test/Ice/exceptions/TestAMDI.cpp b/cpp/test/Ice/exceptions/TestAMDI.cpp index 75cca588a7c..ce0c737e60a 100644 --- a/cpp/test/Ice/exceptions/TestAMDI.cpp +++ b/cpp/test/Ice/exceptions/TestAMDI.cpp @@ -36,13 +36,6 @@ ThrowerI::supportsUndeclaredExceptions_async(const AMD_Thrower_supportsUndeclare } void -ThrowerI::supportsNonIceExceptions_async(const AMD_Thrower_supportsNonIceExceptionsPtr& cb, - const Ice::Current&) -{ - cb->ice_response(false); -} - -void ThrowerI::throwAasA_async(const AMD_Thrower_throwAasAPtr& cb, Ice::Int a, const Ice::Current&) { @@ -76,7 +69,8 @@ ThrowerI::throwBasA_async(const AMD_Thrower_throwBasAPtr& cb, B ex; ex.aMem = a; ex.bMem = b; - cb->ice_exception(ex); + throw ex; + //cb->ice_exception(ex); } void @@ -97,7 +91,8 @@ ThrowerI::throwBasB_async(const AMD_Thrower_throwBasBPtr& cb, B ex; ex.aMem = a; ex.bMem = b; - cb->ice_exception(ex); + throw ex; + //cb->ice_exception(ex); } void @@ -138,7 +133,8 @@ ThrowerI::throwUndeclaredB_async(const AMD_Thrower_throwUndeclaredBPtr& cb, B ex; ex.aMem = a; ex.bMem = b; - cb->ice_exception(ex); + throw ex; +// cb->ice_exception(ex); } void @@ -163,5 +159,5 @@ void ThrowerI::throwNonIceException_async(const AMD_Thrower_throwNonIceExceptionPtr&, const Ice::Current&) { - assert(false); // We cannot throw non-Ice exceptions with AMD. + throw int(12345); } diff --git a/cpp/test/Ice/exceptions/TestAMDI.h b/cpp/test/Ice/exceptions/TestAMDI.h index e6b32ed95a5..b11181aaae5 100644 --- a/cpp/test/Ice/exceptions/TestAMDI.h +++ b/cpp/test/Ice/exceptions/TestAMDI.h @@ -27,8 +27,6 @@ public: const Ice::Current&); virtual void supportsUndeclaredExceptions_async(const AMD_Thrower_supportsUndeclaredExceptionsPtr&, const Ice::Current&); - virtual void supportsNonIceExceptions_async(const AMD_Thrower_supportsNonIceExceptionsPtr&, - const Ice::Current&); virtual void throwAasA_async(const AMD_Thrower_throwAasAPtr&, Ice::Int, const Ice::Current&); diff --git a/cpp/test/Ice/exceptions/TestI.cpp b/cpp/test/Ice/exceptions/TestI.cpp index bea372fb4b5..8042ee0d22c 100644 --- a/cpp/test/Ice/exceptions/TestI.cpp +++ b/cpp/test/Ice/exceptions/TestI.cpp @@ -32,12 +32,6 @@ ThrowerI::supportsUndeclaredExceptions(const Ice::Current&) return true; } -bool -ThrowerI::supportsNonIceExceptions(const Ice::Current&) -{ - return true; -} - void ThrowerI::throwAasA(Ice::Int a, const Ice::Current&) { diff --git a/cpp/test/Ice/exceptions/TestI.h b/cpp/test/Ice/exceptions/TestI.h index 8abb9e16df8..8de265824bd 100644 --- a/cpp/test/Ice/exceptions/TestI.h +++ b/cpp/test/Ice/exceptions/TestI.h @@ -25,7 +25,6 @@ public: virtual void shutdown(const Ice::Current&); virtual bool supportsUndeclaredExceptions(const Ice::Current&); - virtual bool supportsNonIceExceptions(const Ice::Current&); virtual void throwAasA(Ice::Int, const Ice::Current&); virtual void throwAorDasAorD(Ice::Int, const Ice::Current&); |