[omniORB] problems with exceptions and anys

Stefan Seefeld seefeld@sympatico.ca
Mon, 20 Aug 2001 21:06:31 -0500


Duncan Grisby wrote:

 > On Sunday 19 August, Stefan Seefeld wrote:
 >
 >
 >>I have a user exception that I catch in a client and want to report
 >>with a simple '<<' operator. OmniORB complains about
 >>
 >>'Error: function to insert the user exception into an Any is not available'
 >>
 >
 > The root of the problem is that omniORB doesn't define stream <<
 > operators for exceptions, so what you're trying to do isn't valid. I
 > don't know why you're getting messages about Any -- I guess the
 > compiler is very confused and has generated code to do with Anys
 > rather than giving an error.


oh well, I should have thought a bit more before mailing. Here is what happened:
Since there is no predefined output operator for exceptions, I defined it
myself, as suggested by Henning & Vinoski:

inline std::ostream &operator << (std::ostream &os, const CORBA::Exception &exception)
{
CORBA::Any any;
any <<= exception;
CORBA::TypeCode_var tc = any.type();
const char *p = tc->name();
if (*p != '\0') os << p;
else os << tc->id();
return os;
}

All I was missing was to generate stubs with support for any for the exceptions
we define ourselfs. Now all is fine. Sorry for the noise...

Stefan