summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2007-11-15 12:34:24 +1000
committerMichi Henning <michi@zeroc.com>2007-11-15 12:34:24 +1000
commit38be7d804aa9fd784896b492f20017a5b292ee0d (patch)
tree5f65f05cc7de1c234f6d0d83f42c232fcc8215e6 /cpp
parentBut 2534. (diff)
downloadice-38be7d804aa9fd784896b492f20017a5b292ee0d.tar.bz2
ice-38be7d804aa9fd784896b492f20017a5b292ee0d.tar.xz
ice-38be7d804aa9fd784896b492f20017a5b292ee0d.zip
Fixed bug in TestUtil.py that caused line numbers to be omitted from the stack
trace under Mono when the a test failed. Ported servant locator exceptions. Fixed bug that caused the "unknown" member of unknown exception to not be initialized in some cases, and initialized to the wrong value in other cases. Added ice_name() to mapping for exceptions--without it, there was no way to get at the Slice type id of an exception, which was needed to set the "unknown" member correctly.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/src/Ice/Outgoing.cpp4
-rwxr-xr-xcpp/src/Slice/CsUtil.cpp11
-rwxr-xr-xcpp/src/slice2cpp/Gen.cpp8
-rwxr-xr-xcpp/src/slice2cs/Gen.cpp74
-rw-r--r--cpp/test/Ice/servantLocator/AllTests.cpp44
-rw-r--r--cpp/test/Ice/servantLocator/ServantLocatorI.cpp6
6 files changed, 130 insertions, 17 deletions
diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp
index 53c333ba5f8..a46a4e9b0bb 100644
--- a/cpp/src/Ice/Outgoing.cpp
+++ b/cpp/src/Ice/Outgoing.cpp
@@ -67,8 +67,12 @@ IceInternal::LocalExceptionWrapper::throwUnknownWrapper(const std::exception& ex
throw LocalExceptionWrapper(*le, false);
#endif
}
+#if 0
string msg = "std::exception: ";
throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, msg + ex.what()), false);
+#else
+ throw ex;
+#endif
}
const LocalException*
diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp
index 2e392648a50..364f8f3e9aa 100755
--- a/cpp/src/Slice/CsUtil.cpp
+++ b/cpp/src/Slice/CsUtil.cpp
@@ -1540,6 +1540,17 @@ Slice::CsGenerator::MetaDataVisitor::visitStructEnd(const StructPtr&)
void
Slice::CsGenerator::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
+ if(p->hasMetaData("UserException"))
+ {
+ ClassDefPtr cl = ClassDefPtr::dynamicCast(p->container());
+ if(!cl->isLocal())
+ {
+ cout << p->definitionContext()->filename() << ":" << p->line()
+ << ": warning: metdata directive `UserException' applies only to local operations "
+ << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
+ << "' is not local" << endl;
+ }
+ }
validate(p);
}
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index 7694559b5fd..a608a38648b 100755
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -2987,6 +2987,7 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
C << sb;
C << nl << "__direct.servant()->__collocDispatch(__direct);";
C << eb;
+#if 0
C << nl << "catch(const ::std::exception& __ex)";
C << sb;
C << nl << "__direct.destroy();";
@@ -2997,6 +2998,13 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
C << nl << "__direct.destroy();";
C << nl << "throw ::Ice::UnknownException(__FILE__, __LINE__, \"unknown c++ exception\");";
C << eb;
+#else
+ C << nl << "catch(...)";
+ C << sb;
+ C << nl << "__direct.destroy();";
+ C << nl << "throw;";
+ C << eb;
+#endif
C << nl << "__direct.destroy();";
C << eb;
for(ExceptionList::const_iterator k = throws.begin(); k != throws.end(); ++k)
diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp
index 107e5af57dc..a79a7f8333e 100755
--- a/cpp/src/slice2cs/Gen.cpp
+++ b/cpp/src/slice2cs/Gen.cpp
@@ -1855,6 +1855,11 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p)
_out << sp << nl << "#endregion"; // Constructors
+ _out << sp << nl << "public override string ice_name()";
+ _out << sb;
+ _out << nl << "return \"" << p->scoped().substr(2) << "\";";
+ _out << eb;
+
_out << sp << nl << "#region Object members";
_out << sp << nl << "public override int GetHashCode()";
@@ -3876,7 +3881,7 @@ Slice::Gen::DelegateMVisitor::visitClassDefStart(const ClassDefPtr& p)
}
_out << nl << "catch(Ice.UserException ex)";
_out << sb;
- _out << nl << "throw new Ice.UnknownUserException(ex);";
+ _out << nl << "throw new Ice.UnknownUserException(ex.ice_name(), ex);";
_out << eb;
_out << eb;
for(q = outParams.begin(); q != outParams.end(); ++q)
@@ -4038,6 +4043,19 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
ClassDefPtr containingClass = ClassDefPtr::dynamicCast(op->container());
ExceptionList throws = op->throws();
+ throws.sort();
+ throws.unique();
+
+ //
+ // Arrange exceptions into most-derived to least-derived order. If we don't
+ // do this, a base exception handler can appear before a derived exception
+ // handler, causing compiler warnings.
+ //
+#if defined(__SUNPRO_CC)
+ throws.sort(Slice::derivedToBaseCompare);
+#else
+ throws.sort(Slice::DerivedToBaseCompare());
+#endif
vector<string> params = getParams(op);
vector<string> args = getArgs(op);
@@ -4127,10 +4145,11 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
_out << eb;
_out << ";";
- _out << nl << "IceInternal.Direct direct__ = new IceInternal.Direct(current__, run__);";
-
+ _out << nl << "IceInternal.Direct direct__ = null;";
_out << nl << "try";
_out << sb;
+ _out << nl << "direct__ = new IceInternal.Direct(current__, run__);";
+
_out << nl << "Ice.DispatchStatus status__ = direct__.servant().collocDispatch__(direct__);";
if(!throws.empty())
{
@@ -4141,28 +4160,51 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
}
_out << nl << "_System.Diagnostics.Debug.Assert(status__ == Ice.DispatchStatus.DispatchOK);";
+ _out << eb;
+ for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
+ {
+ _out << nl << "catch(" << fixId((*i)->scoped()) << ')';
+ _out << sb;
+ _out << nl << "throw;";
+ _out << eb;
+ }
+ _out << nl << "catch(System.Exception ex__)";
+ _out << sb;
+ _out << nl << "IceInternal.LocalExceptionWrapper.throwUnknownWrapper(ex__);";
+ _out << eb;
+ _out << nl << "finally";
+ _out << sb;
+ _out << nl << "if(direct__ != null)";
+ _out << sb;
+ _out << nl << "try";
+ _out << sb;
+ _out << nl << "direct__.destroy();";
+ _out << eb;
+ for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
+ {
+ _out << nl << "catch(" << fixId((*i)->scoped()) << " ex__)";
+ _out << sb;
+ _out << nl << "throw ex__;";
+ _out << eb;
+ }
+ _out << nl << "catch(System.Exception ex__)";
+ _out << sb;
+ _out << nl << "IceInternal.LocalExceptionWrapper.throwUnknownWrapper(ex__);";
+ _out << eb;
+ _out << eb;
+ _out << eb;
+ //
//
// Set out parameters
//
-
for(vector<string>::iterator s = outHolders.begin(); s != outHolders.end(); ++s)
{
_out << nl << (*s) << " = " << (*s) << "Holder__;";
}
-
- if(ret)
+ if(ret && !containingClass->hasMetaData("amd") && !op->hasMetaData("amd"))
{
_out << nl << "return result__;";
}
- _out << eb;
- _out << nl << "catch(Ice.LocalException ex__)";
- _out << sb;
- _out << nl << "throw new IceInternal.LocalExceptionWrapper(ex__, false);";
- _out << eb;
- _out << nl << "finally";
- _out << sb;
- _out << nl << "direct__.destroy();";
- _out << eb;
}
_out << eb;
}
@@ -4426,7 +4468,7 @@ Slice::Gen::AsyncVisitor::visitOperation(const OperationPtr& p)
}
_out << nl << "catch(Ice.UserException ex)";
_out << sb;
- _out << nl << "throw new Ice.UnknownUserException(ex);";
+ _out << nl << "throw new Ice.UnknownUserException(ex.ice_name(), ex);";
_out << eb;
_out << eb;
for(q = outParams.begin(); q != outParams.end(); ++q)
diff --git a/cpp/test/Ice/servantLocator/AllTests.cpp b/cpp/test/Ice/servantLocator/AllTests.cpp
index 935dafb32e6..38326674a03 100644
--- a/cpp/test/Ice/servantLocator/AllTests.cpp
+++ b/cpp/test/Ice/servantLocator/AllTests.cpp
@@ -61,6 +61,10 @@ testExceptions(const TestIntfPrx& obj, bool collocated)
{
test(ex.unknown == "reason");
}
+ catch(...)
+ {
+ test(false);
+ }
try
{
@@ -71,6 +75,10 @@ testExceptions(const TestIntfPrx& obj, bool collocated)
{
test(ex.unknown == "reason");
}
+ catch(...)
+ {
+ test(false);
+ }
try
{
@@ -112,8 +120,12 @@ testExceptions(const TestIntfPrx& obj, bool collocated)
}
catch(const UnknownException& ex)
{
+ test(!collocated);
test(ex.unknown == "std::exception: Hello");
}
+ catch(const ::std::exception&)
+ {
+ }
catch(...)
{
test(false);
@@ -218,6 +230,38 @@ allTests(const CommunicatorPtr& communicator, bool collocated)
test(obj == base);
cout << "ok" << endl;
+ cout << "testing ice_ids... " << flush;
+ try
+ {
+ ObjectPrx o = communicator->stringToProxy("category/locate:default -p 12010 -t 10000");
+ o->ice_ids();
+ test(false);
+ }
+ catch(const UnknownUserException& ex)
+ {
+ test(ex.unknown == "Test::TestIntfUserException");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+
+ try
+ {
+ ObjectPrx o = communicator->stringToProxy("category/finished:default -p 12010 -t 10000");
+ o->ice_ids();
+ test(false);
+ }
+ catch(const UnknownUserException& ex)
+ {
+ test(ex.unknown == "Test::TestIntfUserException");
+ }
+ catch(...)
+ {
+ test(false);
+ }
+ cout << "ok" << endl;
+
cout << "testing servant locator..." << flush;
base = communicator->stringToProxy("category/locate:default -p 12010 -t 10000");
obj = TestIntfPrx::checkedCast(base);
diff --git a/cpp/test/Ice/servantLocator/ServantLocatorI.cpp b/cpp/test/Ice/servantLocator/ServantLocatorI.cpp
index 37e92f50f0d..a19fd11980d 100644
--- a/cpp/test/Ice/servantLocator/ServantLocatorI.cpp
+++ b/cpp/test/Ice/servantLocator/ServantLocatorI.cpp
@@ -75,7 +75,11 @@ ServantLocatorI::deactivate(const string&)
void
ServantLocatorI::exception(const Ice::Current& current)
{
- if(current.operation == "requestFailedException")
+ if(current.operation == "ice_ids")
+ {
+ throw Test::TestIntfUserException();
+ }
+ else if(current.operation == "requestFailedException")
{
throw Ice::ObjectNotExistException(__FILE__, __LINE__);
}