Go Back   ZeroC Forums > Comments

Reply
 
LinkBack Thread Tools Rating: Thread Rating: 2 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 02-26-2003
andreynech andreynech is offline
Registered User
 
Name: Andrey Nechypurenko
Organization: Siemens AG
Project: remotely controled vehicle
 
Join Date: Feb 2003
Location: Munich, Germany
Posts: 36
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.
Reply With Quote
  #2 (permalink)  
Old 02-26-2003
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 896
Re: Classes vs. Exceptions

Quote:
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.
Reply With Quote
  #3 (permalink)  
Old 02-26-2003
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,780
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.
Reply With Quote
  #4 (permalink)  
Old 02-27-2003
andreynech andreynech is offline
Registered User
 
Name: Andrey Nechypurenko
Organization: Siemens AG
Project: remotely controled vehicle
 
Join Date: Feb 2003
Location: Munich, Germany
Posts: 36
Thank you all very much for the explanations.

Andrey.
Reply With Quote
  #5 (permalink)  
Old 02-28-2003
dthomson dthomson is offline
Registered User
 
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 34
Marc and Michi,

Quote:
Originally posted by Michi
The reason is that not all languages permit you to throw arbitrary types, such as Python and Java.
Quote:
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
Reply With Quote
  #6 (permalink)  
Old 02-28-2003
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,780
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.
Reply With Quote
  #7 (permalink)  
Old 02-28-2003
dthomson dthomson is offline
Registered User
 
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 34
Quote:
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 ...

Quote:
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.

Quote:
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.
Reply With Quote
  #8 (permalink)  
Old 02-28-2003
marlowa marlowa is offline
Registered User
 
 
Join Date: Feb 2003
Location: London
Posts: 64
Quote:
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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# exceptions wrobbie Help Center 7 09-25-2005 07:03 PM
Catching Exceptions chuatecksiong Help Center 3 04-06-2005 01:02 PM
Exceptions cannot be unmarshalled on client robert Bug Reports 4 10-17-2004 11:46 PM
Exceptions and the ice_throw function marlowa Help Center 2 02-28-2003 07:37 AM


All times are GMT -4. The time now is 12:49 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.