summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2007-11-05 23:43:07 +1000
committerMichi Henning <michi@zeroc.com>2007-11-05 23:43:07 +1000
commita2a5af41c5274fa7e254558841c1367d07a445d4 (patch)
treea7ede915600cc8dcb0df48c535bd602ec225e95c /cpp/src
parentFixed bug I introduced with the sequence mapping changes that caused (diff)
downloadice-a2a5af41c5274fa7e254558841c1367d07a445d4.tar.bz2
ice-a2a5af41c5274fa7e254558841c1367d07a445d4.tar.xz
ice-a2a5af41c5274fa7e254558841c1367d07a445d4.zip
Bug 2522 for C++ and Java.
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Direct.cpp5
-rw-r--r--cpp/src/Ice/Outgoing.cpp38
-rw-r--r--cpp/src/Ice/Proxy.cpp76
-rw-r--r--cpp/src/Slice/JavaUtil.cpp11
-rwxr-xr-xcpp/src/slice2cpp/Gen.cpp63
-rw-r--r--cpp/src/slice2java/Gen.cpp138
6 files changed, 261 insertions, 70 deletions
diff --git a/cpp/src/Ice/Direct.cpp b/cpp/src/Ice/Direct.cpp
index a70078d1948..df8ff0ef107 100644
--- a/cpp/src/Ice/Direct.cpp
+++ b/cpp/src/Ice/Direct.cpp
@@ -145,6 +145,10 @@ IceInternal::Direct::destroy()
}
adapter->decDirectCount();
+ if(_userException.get())
+ {
+ _userException->ice_throw();
+ }
}
const ObjectPtr&
@@ -152,4 +156,3 @@ IceInternal::Direct::servant()
{
return _servant;
}
-
diff --git a/cpp/src/Ice/Outgoing.cpp b/cpp/src/Ice/Outgoing.cpp
index d2c70989e72..53c333ba5f8 100644
--- a/cpp/src/Ice/Outgoing.cpp
+++ b/cpp/src/Ice/Outgoing.cpp
@@ -33,6 +33,44 @@ IceInternal::LocalExceptionWrapper::LocalExceptionWrapper(const LocalExceptionWr
_ex.reset(dynamic_cast<LocalException*>(ex.get()->ice_clone()));
}
+void
+IceInternal::LocalExceptionWrapper::throwUnknownWrapper(const std::exception& ex)
+{
+
+ const UserException* ue = dynamic_cast<const UserException*>(&ex);
+ if(ue)
+ {
+ stringstream s;
+ s << *ue;
+ throw LocalExceptionWrapper(UnknownUserException(__FILE__, __LINE__, s.str()), false);
+ }
+
+ const LocalException* le = dynamic_cast<const LocalException*>(&ex);
+ if(le)
+ {
+#if 0
+ //
+ // Commented-out code makes local exceptions fully location transparent,
+ // but the Freeze evictor relies on them not being transparent.
+ //
+ if(dynamic_cast<const UnknownException*>(le) ||
+ dynamic_cast<const ObjectNotExistException*>(le) ||
+ dynamic_cast<const OperationNotExistException*>(le) ||
+ dynamic_cast<const FacetNotExistException*>(le))
+ {
+ throw LocalExceptionWrapper(*le, false);
+ }
+ stringstream s;
+ s << *le;
+ throw LocalExceptionWrapper(UnknownLocalException(__FILE__, __LINE__, s.str()), false);
+#else
+ throw LocalExceptionWrapper(*le, false);
+#endif
+ }
+ string msg = "std::exception: ";
+ throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, msg + ex.what()), false);
+}
+
const LocalException*
IceInternal::LocalExceptionWrapper::get() const
{
diff --git a/cpp/src/Ice/Proxy.cpp b/cpp/src/Ice/Proxy.cpp
index b902dedaad1..35ee8cae257 100644
--- a/cpp/src/Ice/Proxy.cpp
+++ b/cpp/src/Ice/Proxy.cpp
@@ -1354,16 +1354,29 @@ IceDelegateD::Ice::Object::ice_isA(const string& __id, const Context* context)
{
__direct.servant()->__collocDispatch(__direct);
}
+ catch(const ::std::exception& __ex)
+ {
+ __direct.destroy();
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
catch(...)
{
__direct.destroy();
- throw;
+ throw UnknownException(__FILE__, __LINE__, "unknown c++ exception");
}
__direct.destroy();
}
- catch(const LocalException& __ex)
+ catch(const LocalExceptionWrapper&)
+ {
+ throw;
+ }
+ catch(const ::std::exception& __ex)
+ {
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
+ catch(...)
{
- throw LocalExceptionWrapper(__ex, false);
+ throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, "unknown c++ exception"), false);
}
return __result;
}
@@ -1399,16 +1412,29 @@ IceDelegateD::Ice::Object::ice_ping(const ::Ice::Context* context)
{
__direct.servant()->__collocDispatch(__direct);
}
+ catch(const ::std::exception& __ex)
+ {
+ __direct.destroy();
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
catch(...)
{
__direct.destroy();
- throw;
+ throw UnknownException(__FILE__, __LINE__, "unknown c++ exception");
}
__direct.destroy();
}
- catch(const LocalException& __ex)
+ catch(const LocalExceptionWrapper&)
+ {
+ throw;
+ }
+ catch(const ::std::exception& __ex)
+ {
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
+ catch(...)
{
- throw LocalExceptionWrapper(__ex, false);
+ throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, "unknown c++ exception"), false);
}
}
@@ -1449,16 +1475,29 @@ IceDelegateD::Ice::Object::ice_ids(const ::Ice::Context* context)
{
__direct.servant()->__collocDispatch(__direct);
}
+ catch(const ::std::exception& __ex)
+ {
+ __direct.destroy();
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
catch(...)
{
__direct.destroy();
- throw;
+ throw UnknownException(__FILE__, __LINE__, "unknown c++ exception");
}
__direct.destroy();
}
- catch(const LocalException& __ex)
+ catch(const LocalExceptionWrapper&)
+ {
+ throw;
+ }
+ catch(const ::std::exception& __ex)
+ {
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
+ catch(...)
{
- throw LocalExceptionWrapper(__ex, false);
+ throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, "unknown c++ exception"), false);
}
return __result;
}
@@ -1500,16 +1539,29 @@ IceDelegateD::Ice::Object::ice_id(const ::Ice::Context* context)
{
__direct.servant()->__collocDispatch(__direct);
}
+ catch(const ::std::exception& __ex)
+ {
+ __direct.destroy();
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
catch(...)
{
__direct.destroy();
- throw;
+ throw UnknownException(__FILE__, __LINE__, "unknown c++ exception");
}
__direct.destroy();
}
- catch(const LocalException& __ex)
+ catch(const LocalExceptionWrapper&)
+ {
+ throw;
+ }
+ catch(const ::std::exception& __ex)
+ {
+ LocalExceptionWrapper::throwUnknownWrapper(__ex);
+ }
+ catch(...)
{
- throw LocalExceptionWrapper(__ex, false);
+ throw LocalExceptionWrapper(UnknownException(__FILE__, __LINE__, "unknown c++ exception"), false);
}
return __result;
}
diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp
index 8f27fb78708..a116b1a7a95 100644
--- a/cpp/src/Slice/JavaUtil.cpp
+++ b/cpp/src/Slice/JavaUtil.cpp
@@ -3442,6 +3442,17 @@ Slice::JavaGenerator::MetaDataVisitor::visitStructStart(const StructPtr& p)
void
Slice::JavaGenerator::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: metadata directive `UserException' applies only to local operations "
+ << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
+ << "' is not local" << endl;
+ }
+ }
StringList metaData = getMetaData(p);
TypePtr returnType = p->returnType();
if(!metaData.empty())
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp
index ba7db40f1a4..2196a6953b5 100755
--- a/cpp/src/slice2cpp/Gen.cpp
+++ b/cpp/src/slice2cpp/Gen.cpp
@@ -2926,7 +2926,11 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
if(!throws.empty())
{
C << eb;
-
+ C << nl << "catch(const ::Ice::UserException& __ex)";
+ C << sb;
+ C << nl << "setUserException(__ex);";
+ C << nl << "return ::Ice::DispatchUserException;";
+ C << eb;
throws.sort();
throws.unique();
#if defined(__SUNPRO_CC)
@@ -2935,14 +2939,6 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
throws.sort(Slice::DerivedToBaseCompare());
#endif
- for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
- {
- C << nl << "catch(const " << fixKwd((*i)->scoped()) << "& e)";
- C << sb;
- C << nl << "setUserException(e);";
- C << nl << "return ::Ice::DispatchUserException;";
- C << eb;
- }
}
C << eb;
@@ -2989,28 +2985,39 @@ Slice::Gen::DelegateDVisitor::visitOperation(const OperationPtr& p)
C << nl << "try";
C << sb;
- if(!throws.empty())
+ C << nl << "__direct.servant()->__collocDispatch(__direct);";
+ C << eb;
+ C << nl << "catch(const ::std::exception& __ex)";
+ C << sb;
+ C << nl << "__direct.destroy();";
+ C << nl << "::IceInternal::LocalExceptionWrapper::throwUnknownWrapper(__ex);";
+ C << eb;
+ C << nl << "catch(...)";
+ C << sb;
+ C << nl << "__direct.destroy();";
+ C << nl << "throw ::Ice::UnknownException(__FILE__, __LINE__, \"unknown c++ exception\");";
+ C << eb;
+ C << nl << "__direct.destroy();";
+ C << eb;
+ for(ExceptionList::const_iterator i = throws.begin(); i != throws.end(); ++i)
{
- C << nl << "if(__direct.servant()->__collocDispatch(__direct) == ::Ice::DispatchUserException)";
+ C << nl << "catch(const " << fixKwd((*i)->scoped()) << "&)";
C << sb;
- C << nl << "__direct.throwUserException();";
+ C << nl << "throw;";
C << eb;
}
- else
- {
- C << nl << "__direct.servant()->__collocDispatch(__direct);";
- }
- C << eb;
- C << nl << "catch(...)";
+ C << nl << "catch(const ::IceInternal::LocalExceptionWrapper&)";
C << sb;
- C << nl << "__direct.destroy();";
C << nl << "throw;";
C << eb;
- C << nl << "__direct.destroy();";
+ C << nl << "catch(const ::std::exception& __ex)";
+ C << sb;
+ C << nl << "::IceInternal::LocalExceptionWrapper::throwUnknownWrapper(__ex);";
C << eb;
- C << nl << "catch(const ::Ice::LocalException& __ex)";
+ C << nl << "catch(...)";
C << sb;
- C << nl << "throw ::IceInternal::LocalExceptionWrapper(__ex, false);";
+ C << nl << "throw ::IceInternal::LocalExceptionWrapper("
+ << "::Ice::UnknownException(__FILE__, __LINE__, \"unknown c++ exception\"), false);";
C << eb;
if(ret)
{
@@ -5615,6 +5622,18 @@ Slice::Gen::MetaDataVisitor::visitOperation(const OperationPtr& p)
{
ami = true;
}
+
+ if(p->hasMetaData("UserException"))
+ {
+ if(!cl->isLocal())
+ {
+ cout << p->definitionContext()->filename() << ":" << p->line()
+ << ": warning: metadata directive `UserException' applies only to local operations "
+ << "but enclosing " << (cl->isInterface() ? "interface" : "class") << "`" << cl->name()
+ << "' is not local" << endl;
+ }
+ }
+
StringList metaData = p->getMetaData();
metaData.remove("cpp:const");
diff --git a/cpp/src/slice2java/Gen.cpp b/cpp/src/slice2java/Gen.cpp
index 471ecabc6ca..1b4f40edf09 100644
--- a/cpp/src/slice2java/Gen.cpp
+++ b/cpp/src/slice2java/Gen.cpp
@@ -540,7 +540,16 @@ Slice::JavaVisitor::writeDispatchAndMarshalling(Output& out, const ClassDefPtr&
{
out << sp << nl << "public final " << typeToString(ret, TypeModeReturn, package, op->getMetaData())
<< nl << opName << spar << params << epar;
- writeThrowsClause(package, throws);
+ if(op->hasMetaData("UserException"))
+ {
+ out.inc();
+ out << nl << "throws Ice.UserException";
+ out.dec();
+ }
+ else
+ {
+ writeThrowsClause(package, throws);
+ }
out << sb << nl;
if(ret)
{
@@ -1430,7 +1439,16 @@ Slice::Gen::OpsVisitor::writeOperations(const ClassDefPtr& p, bool noCurrent)
out << "Ice.Current __current";
}
out << epar;
- writeThrowsClause(package, throws);
+ if(op->hasMetaData("UserException"))
+ {
+ out.inc();
+ out << nl << "throws Ice.UserException";
+ out.dec();
+ }
+ else
+ {
+ writeThrowsClause(package, throws);
+ }
out << ';';
}
@@ -1595,10 +1613,19 @@ Slice::Gen::TieVisitor::visitClassDefStart(const ClassDefPtr& p)
}
out << epar;
- ExceptionList throws = (*r)->throws();
- throws.sort();
- throws.unique();
- writeThrowsClause(package, throws);
+ if((*r)->hasMetaData("UserException"))
+ {
+ out.inc();
+ out << nl << "throws Ice.UserException";
+ out.dec();
+ }
+ else
+ {
+ ExceptionList throws = (*r)->throws();
+ throws.sort();
+ throws.unique();
+ writeThrowsClause(package, throws);
+ }
out << sb;
out << nl;
if(ret && !hasAMD)
@@ -4325,7 +4352,10 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
out << nl << "final " << resultTypeHolder << " __result = new " << resultTypeHolder << "();";
}
- out << nl << "IceInternal.Direct __direct = new IceInternal.Direct(__current)";
+ out << nl << "IceInternal.Direct __direct = null;";
+ out << nl << "try";
+ out << sb;
+ out << nl << "__direct = new IceInternal.Direct(__current)";
out << sb;
out << nl << "public Ice.DispatchStatus run(Ice.Object __obj)";
out << sb;
@@ -4352,7 +4382,6 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
}
out << "__servant." << opName << spar << args << "__current" << epar << ';';
out << nl << "return Ice.DispatchStatus.DispatchOK;";
-
if(!throws.empty())
{
out << eb;
@@ -4362,50 +4391,80 @@ Slice::Gen::DelegateDVisitor::visitClassDefStart(const ClassDefPtr& p)
out << nl << "return Ice.DispatchStatus.DispatchUserException;";
out << eb;
}
+
out << eb;
out << eb;
out << ";";
- out << nl << "try";
+ out << sp << nl << "Ice.DispatchStatus __status = __direct.servant().__collocDispatch(__direct);";
+ out << nl << "if(__status == Ice.DispatchStatus.DispatchUserException)";
out << sb;
- out << nl << "Ice.DispatchStatus __status = __direct.servant().__collocDispatch(__direct);";
- if(!throws.empty())
- {
- out << nl << "if(__status == Ice.DispatchStatus.DispatchUserException)";
- out << sb;
- out << nl << "try";
- out << sb;
- out << nl << "__direct.throwUserException();";
- out << eb;
- for(ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t)
- {
- string exS = getAbsolute(*t, package);
- out << nl << "catch(" << exS << " __ex)";
- out << sb;
- out << nl << "throw __ex;";
- out << eb;
- }
- out << nl << "catch(Ice.UserException __ex)";
- out << sb;
- out << nl << "assert false;";
- out << nl << "throw new Ice.UnknownUserException(__ex.toString());";
- out << eb;
- out << eb;
- }
+ out << nl << "__direct.throwUserException();";
+ out << eb;
out << nl << "assert __status == Ice.DispatchStatus.DispatchOK;";
if(ret)
{
out << nl << "return __result.value;";
}
+
out << eb;
+ for(ExceptionList::const_iterator t = throws.begin(); t != throws.end(); ++t)
+ {
+ string exS = getAbsolute(*t, package);
+ out << nl << "catch(" << exS << " __ex)";
+ out << sb;
+ out << nl << "throw __ex;";
+ out << eb;
+ }
+
+ //
+ // Next two catch handlers keep local exceptions non-transparent.
+ //
+ out << nl << "catch(Ice.UserException __ex)";
+ out << sb;
+ out << nl << "IceInternal.LocalExceptionWrapper.throwUnknownWrapper(__ex);";
+ out << eb;
+ out << nl << "catch(Ice.LocalException __ex)";
+ out << sb;
+ out << nl << "IceInternal.LocalExceptionWrapper.throwUnknownWrapper(__ex);";
+ out << eb;
+
+ /*
+ //
+ // Commented-out code makes local exceptions fully location transparent,
+ // but the Freeze evictor relies on them being non-transparent.
+ //
out << nl << "catch(Ice.LocalException __ex)";
out << sb;
- out << nl << "throw new IceInternal.LocalExceptionWrapper(__ex, false);";
+ 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 t = throws.begin(); t != throws.end(); ++t)
+ {
+ string exS = getAbsolute(*t, package);
+ out << nl << "catch(" << exS << " __ex)";
+ out << sb;
+ out << nl << "throw __ex;";
+ out << eb;
+ }
+ out << nl << "catch(java.lang.Throwable __ex)";
+ out << sb;
+ out << nl << "IceInternal.LocalExceptionWrapper.throwUnknownWrapper(__ex);";
+ out << eb;
+ out << eb;
+ out << eb;
+ }
+ if(ret && !cl->hasMetaData("amd") && !op->hasMetaData("amd"))
+ {
+ out << nl << "return __result.value;";
}
out << eb;
}
@@ -4688,7 +4747,16 @@ Slice::Gen::BaseImplVisitor::writeOperation(Output& out, const string& package,
throws.sort();
throws.unique();
- writeThrowsClause(package, throws);
+ if(op->hasMetaData("UserException"))
+ {
+ out.inc();
+ out << nl << "throws Ice.UserException";
+ out.dec();
+ }
+ else
+ {
+ writeThrowsClause(package, throws);
+ }
out << sb;