Archived

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

C# AMI exception handling on client

Ice 3.3

Exception of type derived from Ice::UserException is thrown on a server inside AMI asynchronous call.
Client receives this exception through ice_exception method provided by the client callback.

Client is written on C#. Server side is C++.

The problem is UnknownUserException type is posted to the ice_exception callback instead of my user exception type.

How to catch my own exception type on the client side?

clent code:

public class ClientCallback : coordinator.AMI_IJob_Start
{

public override void ice_response()
{
}

public override void ice_exception(Ice.Exception ex)
{
// ex is of UnknownUserException type why?
}

}

Comments

  • bernard
    bernard Jupiter, FL
    Hi Leonid,

    You need to add your exception to the exception specification of the corresponding Slice operation. Otherwise, Ice transforms this exception into an UnknownUserException.

    Cheers,
    Bernard
  • Thanks, Bernard.

    This really helps. The problem was in ice definition.

    the function was declared as throwing exception of type ServerEx which is derived from class RootEx.

    exception RootEx
    {
    };

    exception ServerEx extends RootEx
    {
    };

    interface Server
    {
    void Add( ServerItem item ) throws ServerEx;
    }

    If I try to throw RootEx exception from a server side it is catched as UnknownUserException on a client until I define this:

    interface Server
    {
    void Add( ServerItem item ) throws ServerEx, RootEx;
    }

    Doesn't look strange? ServerEx is derived from RootEx so RootEx must be catched on client as well. Another way I would have to define the whole chain of derived classes as possible types to throw :(
  • bernard
    bernard Jupiter, FL
    Hi Leonid,

    You can list only the root exception of your user-exception hierarchy (RootEx) in the Slice exception specification. See "Exception Inheritance" in the Ice manual for full details!

    Cheers,
    Bernard