Archived

This forum has been archived. Please start a new discussion on GitHub.

local exception / C++

I'm using the MacOS Binary 2.1.2 binary distribution.

With the following slice file, exception.ice...

module test {
local exception TestException {
string message;
string cause;
string stackTrace;
};
};

slice2cpp creates exception.h and exception.cpp

The code generated for exception.h includes...

namespace test
{
class TestException : public ::Ice::LocalException
{
public:
TestException(const char*, int);
virtual const ::std::string& ice_name() const;
virtual void ice_print(::std::ostream&) const;
virtual ::Ice::Exception* ice_clone() const;
virtual void ice_throw() const;
::std::string message;
::std::string cause;
::std::string stackTrace;
};
}

Notice the functions: ice_name, ice_print, ice_clone, and ice_throw.

The cpp file, exception.cpp, includes function stubs for ice_name, ice_clone, and ice_throw, but NOT ice_print...

test::TestException::TestException(const char* file, int line) :
::Ice::LocalException(file, line)
{
}

static const ::std::string __test__TestException_name = "test::TestException";

const ::std::string&
test::TestException::ice_name() const
{
return __test__TestException_name;
}

::Ice::Exception*
test::TestException::ice_clone() const
{
return new TestException(*this);
}

void
test::TestException::ice_throw() const
{
throw *this;
}

My question: Is this proper behavior for slice2cpp, or should it have provided an ice_print function?

I can edit the generated file, or I can add a function in a different file. But I thought I should ask first. Perhaps there's something else I'm doing wrong.

Comments

  • Smiley

    The line with the smiley should read:

    virtual void ice_print(::std::ostream&) const;
  • Signature required ...

    Okay, here's my signature.
  • benoit
    benoit Rennes, France
    Hi Daniel,

    Yes, that's the proper behavior for local exceptions. The ice_print method needs to be implemented separately (for example, ice_print is implemented in src/Ice/Exception.cpp for Ice local exceptions). Is there any reasons why you use local exceptions over regular Slice exceptions?

    Benoit.
  • Why use local exceptions

    Greetings, Benoit. Thanks for checking on my post.

    The decision to use local exceptions came from someone on the Java side of the team.

    Here is the explaination that was given to me:

    > FCAAuthenticationException is thrown from the various services at fca when
    > authentication fails.
    > Its was made a local exception so the resulting class generated in java
    > using slice2java can be a
    > runtime exception. This way the various services can throw this exception
    > without explicitly defining
    > this exception the method signatures in slice definition.
    >
    > For example the method submitMonitoredSearch() in the servant class derived
    > from the following slice definition can throw
    > a FCAAuthenticationException from submitMonitoredSearch() without explicitly
    > declaring it in the exception specification of the method.
    >
    > interface FCAICESearchService {
    > string submitMonitoredSearch(FCASearchRequest searchRequest)
    > throws DatabaseException,SearchException;
    > }
    >
    > If we are to remove local then we need to changes the all the services to
    > explicitly throw this exception.
    > So the above definition will look like,
    > interface FCAICESearchService {
    > string submitMonitoredSearch(FCASearchRequest searchRequest)
    > throws
    > DatabaseException,SearchException,FCAAuthenticationException
    > }

    I will request that the ice files be modified to remove any include dependency on local structures in the ice files required by the server. But if that is not possible, I can implement ice_print in a separate file and link it in with the server.

    Thank you for your help.
  • benoit
    benoit Rennes, France
    Note that local exceptions are not marshalled over the wire (with the exception of exceptions derived from Ice::RequestFailedException). If a servant raises a local exception, it won't be received by the client as is, the client will instead get an Ice::UnknownLocalException.

    In your case, if a client invokes FCAICESearchService::submitMonitoredSearch and this method raises FCAAuthenticationException, the client will get an Ice::UnknownLocalException.

    If the FCAAuthenticationException exception isn't supposed to go over the wire but is an internal exception to your Java service, I would recommend to simply use a regular Java exception instead of a Slice local exception.

    Benoit.
  • :-)

    Thank you. I'll forward your suggestion to the team architect.