Preliminary documentation for Ice 3.7.1 Beta. Do not use in production applications. Refer to the space directory for other releases.

To throw an exception from an operation implementation, you simply allocate the exception, initialize it, and throw it. For example:

Objective-C
-(void) write:(NSMutableArray *)text current:(ICECurrent *)current
{
    // Try to write the file contents here...
    // Assume we are out of space...
    if(error)
    {
        @throw [FSGenericError genericError:@"file too large"];
    }
}

As for out-parameters and return values, you must take care to throw an autoreleased exception if you are not using ARC.

If you throw an arbitrary Objective-C exception that does not derive from ICEException, the client receives an UnknownException.

The server-side Ice run time does not validate user exceptions thrown by an operation implementation to ensure they are compatible with the operation's Slice definition. Rather, Ice returns the user exception to the client, where the client-side run time will validate the exception as usual and raise UnknownUserException for an unexpected exception type.

If you throw an Ice run-time exception, such as MemoryLimitException, the client receives an UnknownLocalException. For that reason, you should never throw Ice run-time exceptions from operation implementations. If you do, all the client will see is an UnknownLocalException, which does not tell the client anything useful.

Three run-time exceptions are treated specially and not changed to UnknownLocalException when returned to the client: ObjectNotExistException, OperationNotExistException, and FacetNotExistException.

See Also

  • No labels