Archived

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

Runtime Exception

Hi,

I know ice has a bunch of predefined runtime exceptions, but I cant seem to find a way to make user defined runtime exception. Is there anyway to do this or will i just have to settle with making UnknownLocalExceptions

Comments

  • marc
    marc Florida
    Ice has local and non-local exceptions. Local exceptions are also referred to as runtime exceptions, since they are used by the Ice runtime to indicate local failures, such as when the runtime runs out of sockets, memory, if there is a timeout, etc.

    Except for RequestFailedException and its derivates (ObjectNotExistException, OperationNotExistException, and FacetNotExistException), these exceptions have only meaning in the local process. As such, they are not transferred to a client. If they are raised, then a client will get an UnknownLocalException.

    Your own code should neither raise (except for RequestFailedException and derived exceptions) nor define these exceptions. If you want to define local exception that are not transmitted, do so directly in your concrete programming language. If you want exceptions that are transmitted to the client, then define regular exceptions.
  • Thank you for such a quick reply

    The purpose of wanting a user defined runtime exception was to allow the server to throw something in order to tell the client to clear its locator cache and do another registry lookup. And as this can occur with any method call it would be inconvenaint to have to explicitly state that for every method

    However ive come across a way for the server to clear the clients cache and im not entirely sure why it works, or even if it should work. By getting my server to run
    __current.con.close(false);
    throw new Ice.ObjectNotExistException(__current.id, __current.facet, __current.operation);
    
    the client not only automatically trys to reconnect but it also clears its locator cache. Is this behaviour something that would be caused by another piece of my code i missed, a rather convenient bug or intended behavoiur?
  • benoit
    benoit Rennes, France
    Hi,

    Why do you need the server to notify the client to clear its locator cache?

    The Ice runtime clears from the locator cache the endpoints of an indirect proxy for a well-known object if it receives an Ice::ObjectNotExistException. I suspect that's the reason why it works with the code you mention (you shouldn't need to close the connection though).

    Cheers,
    Benoit.
  • marc wrote: »
    Your own code should neither raise (except for RequestFailedException and derived exceptions) nor define these exceptions. If you want to define local exception that are not transmitted, do so directly in your concrete programming language.

    When trying to provide a unified API in multiple languages, would it perhaps make sense to use local exceptions. Specifically, we're mapping our domain model into Ice. Some relationships require client-side methods to maintain consistency. E.g.
    module omero {
      module model {
        sequence<omero::model::Image> ImageSeq;
        class Pixels
        {
         ImageSeq images;
         void addImage(omero::model::Image img);
        }
      }
    }
    
    which also ensures that the other side of the relationship is properly set. With a local exception of the form:
    module omero {
        local exception ClientError
        {
          string message;
        };
    }
    
    I could add the exception to that addImage:
    void addImage(omero::model::Image img) throws ClientError;
    
    so it's clear in all bindings what's intended.