Table of Contents Previous Next
Logo
Server-Side Slice-to-Objective‑C Mapping : 20.6 Raising Exceptions
Copyright © 2003-2009 ZeroC, Inc.

20.6 Raising Exceptions

To throw an exception from an operation implementation, you simply allocate the exception, initialize it, and throw it. For example:
(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 throw an "impossible" user exception (a user exception that is not listed in the exception specification of the operation), the client receives an UnknownUserException.
If you throw a run-time exception, such as MemoryLimitException, the client receives an UnknownLocalException.1 For that reason, you should never throw system exceptions from operation implementations. If you do, all the client will see is an UnknownLocalException, which does not tell the client anything useful.
If you throw an arbitrary Objective‑C exception that does not derive from ICEException, the client receives an UnknownException.

1
There are three system exceptions that are not changed to UnknownLocalException when returned to the client: ObjectNotExistException, OperationNotExistException, and FacetNotExistException. We discuss these exceptions in more detail in Section 4.10.4 and Chapter 34.

Table of Contents Previous Next
Logo