Results 1 to 8 of 8

Thread: Classes vs. Exceptions

  1. #1
    andreynech is offline Registered User
    Name: Andrey Nechypurenko
    Organization: GE Healthcare
    Project: hobby remotely controled vehicle
    Join Date
    Feb 2003
    Location
    Munich, Germany
    Posts
    59

    Classes vs. Exceptions

    Hi,

    Taking in account the idea of making Slice more simple as CORBA IDL by removing unnecessary and redundant featrues I would like to ask about the motivations to introduce Exceptions as a separate entity. Would not it be possible to allow throwing any structures or classes? I understand that some languages (like Java) expose additional requirements to the type to make it possible to throw it (Throwable) but maybe Slice compiler could be smart enough to generate corresponding code if necessary? I am just curious and would be glad if somebody could comment on this topic.

    Thank you,
    Andrey.

  2. #2
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055

    Re: Classes vs. Exceptions

    Originally posted by andreynech
    Hi,

    Taking in account the idea of making Slice more simple as CORBA IDL by removing unnecessary and redundant featrues I would like to ask about the motivations to introduce Exceptions as a separate entity. Would not it be possible to allow throwing any structures or classes? I understand that some languages (like Java) expose additional requirements to the type to make it possible to throw it (Throwable) but maybe Slice compiler could be smart enough to generate corresponding code if necessary? I am just curious and would be glad if somebody could comment on this topic.

    Thank you,
    Andrey.
    Yes, we considered doing this at length. In fact, I was one of the major proponents of that. In the end we decided against it. The reason is that not all languages permit you to throw arbitrary types, such as Python and Java. Yes, we could have packed non-exception types into a language-native exception type for such languages, but then the simplicity is lost again at the language level.

    We went through similar arguments with classes and structs: why have inheritance on classes but not on structs? The reasoning here was that plain structs are more efficient and can be marshaled with less overhead and mapped to a language-native plain struct, whereas, for classes, we have more overhead due to the need to deal with derivation. In the end, retaining plain structs as a separate type was seen as the right compromise.

    Cheers,

    Michi.

  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
    I'm afraid it's more languages than only Java.

    For Java, we would basically have to make every class throwable, because every class might potentially be an exception. For other languages, it would be even worse. For example, exceptions in Python are separate from the normal type system.

    In addition, I believe that a separate exception type also provides more clarity to Slice code.

  4. #4
    andreynech is offline Registered User
    Name: Andrey Nechypurenko
    Organization: GE Healthcare
    Project: hobby remotely controled vehicle
    Join Date
    Feb 2003
    Location
    Munich, Germany
    Posts
    59
    Thank you all very much for the explanations.

    Andrey.

  5. #5
    dthomson is offline Registered User
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    34
    Marc and Michi,

    Originally posted by Michi
    The reason is that not all languages permit you to throw arbitrary types, such as Python and Java.
    Originally posted by marc
    For example, exceptions in Python are separate from the normal type system.
    This is news to me, and I've done a little Python What do you mean? I can throw any object as an exception in Python. Including built-in types like strings and integers.

    BTW I agree with your decision with regards to keeping exceptions a separate type in Slice.

    Here's some examples:

    Code:
    #!/usr/bin/env python
    
    # Define an exception class.
    # Note that there's nothing special about it!
    
    class SomeException:
        def __init__(self, msg, severity):
            """Create an instance of the exception class"""
            
            self.msg = msg
            self.severity = severity
    
        def __str__(self):
            """Convert the exception to a string"""
    
            return ("SomeException (msg:%s, severity: %d)" %
                      (self.msg, self.severity))
    
    # Throw an instance of the new class
    
    try:
        
        raise SomeException('Bad craziness', 42)
    
    except SomeException, e:
        
        print 'Caught:', e

  6. #6
    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
    We worked on a project called "Pyce" (Ice for Python) some time ago. At this time, Ice still allowed "everything to be an exception", and we had a lot of trouble implementing this model with the Python/C API.

    However, it is quite possible that we simply did something wrong. We are no Python gurus. In any case, I can't remember the details, it's too long ago, and Pyce is now on hold.

    If someone with more Python experience wants to pick up Pyce, we would of course be more than happy to help whereever we can Ice for Python would definitely be very cool.

  7. #7
    dthomson is offline Registered User
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    34
    Originally posted by marc
    We worked on a project called "Pyce" (Ice for Python) some time ago. At this time, Ice still allowed "everything to be an exception", and we had a lot of trouble implementing this model with the Python/C API.
    That's quite a reasonable excuse, actually. The Python/C API is under-documented, especially when it comes to implementing true Python classes in C.

    Implementing simple functions is fine ... but the rules for implementing new classes in C only existed in skeleton form in the documentation last time I looked. One of my plans is to figure it out and update the documentation. One of these days ...

    However, it is quite possible that we simply did something wrong. We are no Python gurus. In any case, I can't remember the details, it's too long ago, and Pyce is now on hold
    It certainly should have worked. That said, there may also have been some bizarre bug in the Python/C API layer causing extension classes not to be implemented properly so that they can't be thrown. I will definitely try this when I get the chance, and if it doesn't work raise it with the Python dev team.

    If someone with more Python experience wants to pick up Pyce, we would of course be more than happy to help whereever we can Ice for Python would definitely be very cool.
    If that's a hint, I'm way, way, way, too busy! I'm supporting two scripting ORBs in my own time at the moment, and that is too much I'm afraid. And I'm supposed to be having a break! So, much as I'd like to, I can't right now.

  8. #8
    marlowa is offline Registered User
    Join Date
    Feb 2003
    Location
    London
    Posts
    64
    Originally posted by marc
    We worked on a project called "Pyce" (Ice for Python)
    If this project ever gets resurrected you could call it 'CrushedIce'. Groan!

    -Andrew
    You are in a maze of twisty little passages, all different.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Serializing Exceptions
    By halfhp in forum Help Center
    Replies: 2
    Last Post: 02-18-2010, 03:45 AM
  2. Icepatch exceptions
    By Skip in forum Bug Reports
    Replies: 2
    Last Post: 06-27-2007, 06:29 AM
  3. IceGridAdmin exceptions
    By ctennis in forum Bug Reports
    Replies: 2
    Last Post: 04-09-2007, 11:37 AM
  4. C# exceptions
    By wrobbie in forum Help Center
    Replies: 7
    Last Post: 09-25-2005, 07:03 PM
  5. Catching Exceptions
    By chuatecksiong in forum Help Center
    Replies: 3
    Last Post: 04-06-2005, 01:02 PM

Posting Permissions

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