Results 1 to 5 of 5

Thread: Mapping Exception

  1. #1
    ganzuoni is offline Registered User
    Name: Guido Anzuoni
    Organization: Individual
    Project: No specific project
    Join Date
    Jun 2003
    Location
    Italy
    Posts
    49

    Mapping Exception

    Hi,

    it would be nice to have the possibility to specify exceptions that
    represent general runtime errors at object implementation level that,
    in Java, would be derived from java.lang.RuntimeException.

    Consider the following:

    module sample {

    // marked somehow to derive from
    // java.lang.RuntimeException, unchecked keyword ??
    exception SystemError {
    string message;
    }

    exception OutOfMemoryError extends SystemError {
    }


    interface RemoteService {

    void doSomething(); // no throws clause for SystemError
    }

    }

    Two benefits: first you don't have the add "throw SystemError" to all
    the operations of an interface; second, the client is not aware of
    implementation details in the normal case (it is aware only of
    "logic" errors).

    Regards,
    Guido.

  2. #2
    domak is offline Registered User
    Name: Christophe Domas
    Organization: Christophe Domas Consultant
    Project: none
    Join Date
    Feb 2008
    Posts
    1
    Hi,
    I'm also interested by this.
    We have a lot of slices already defined without exception (ok, that's bad). Actually, clients catch UnknownException (ok, that's worst).
    I would like to introduce a new exception hierarchy without modifying the slices, by throwing RuntimeException.

    Is it possible?

  3. #3
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    No, this is not possible. Ice has to know about the exceptions that can be raised (i.e., exceptions must be defined in Slice), otherwise it cannot know how to marshal them.

    We might add the option for the user to define runtime exceptions in a future version of Ice, but these would have to be defined in Slice as well. The only difference to user exceptions would be that these are "unchecked" exceptions, i.e., they would not have to appear in the throws clause of operations. (Note that this would be a very intrusive change to Ice, so while it is on our todo list, don't expect this anytime soon.)

    Having said this, I don't think such runtime exceptions should be used where user exceptions (exceptions listed in the throws clause of operations) are more appropriate.

  4. #4
    GaryD is offline Registered User
    Name: Gary Donovan
    Organization: Crucial Fruit
    Project: CRM for charities
    Join Date
    Mar 2009
    Location
    Australia
    Posts
    25
    Hi guys,

    I have been pondering this too. A lot of java libraries nowadays rely simply on unchecked exceptions, and this is certainly my preference.

    That said, there appear to be 2 "simple" ways to achieve this:
    * Have an alternate Java mapping where Ice.UserException derives from RuntimeException instead of Exception.
    * Use Slice metadata to indicate which Slice exceptions are unchecked (defaulting to checked exceptions). In the Java mapping, have Ice.UserException (as with the current situation) for standard exceptions, and a new exception hierarchy based on Ice.UncheckedUserException (derived from RuntimeException) for the unchecked ones.

    Any thoughts?

  5. #5
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Gary,

    At the Slice level, user exceptions must remain "checked" (explicitly listed by operations that raise them), because slice2java (slice2cpp etc.) generates code to handle them.

    At the Java level, we could indeed provide metadata to allow you to map your user exceptions to Runtime exceptions (your second option). Your first option - an alternate mapping, with its separate Ice.jar file - sounds a bit excessive.

    Best regards,
    Bernard
    Bernard Normier
    ZeroC, Inc.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. user exception causes unmarshalling exception
    By Stuart Brodsky in forum Help Center
    Replies: 9
    Last Post: 04-29-2009, 02:21 PM
  2. Obj-C Mapping
    By slypete in forum Bug Reports
    Replies: 5
    Last Post: 01-28-2009, 09:46 PM
  3. Best practice for exception mapping
    By HpGisler in forum Help Center
    Replies: 1
    Last Post: 06-25-2007, 06:16 PM
  4. Replies: 2
    Last Post: 12-13-2006, 10:52 AM
  5. C mapping
    By colding in forum Comments
    Replies: 4
    Last Post: 03-31-2005, 04:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •