Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 03-25-2004
peter.s peter.s is offline
Registered User
 
 
Join Date: Mar 2004
Posts: 12
Exception reordering in C++ interface

slice2cpp creates cpp files where the exceptions which are caught and thrown/marshalled are not in the same order as they are in the .ice file.

i created the following example code to illustrate my problem:

Code:
module bla {

        exception Parent {};
        exception Child extends Parent {};
        exception XChild extends Parent {};

        interface bli {
                void testi1() throws Parent, Child;
                void testi2() throws Child, Parent;
                void testi3() throws Parent, XChild;
                void testi4() throws XChild, Parent;
        };

};
the cpp file created by slice2cpp contains instructions to catch _each_ of the exceptions thrown by a method.

the problem is, they are caught in alphabetical order, thus i get the following warnings from g++ if i try to compile the generated files:

Code:
test_exception_throwing.cpp: In member function `IceInternal::DispatchStatus 
   bla::bli::___testi3(IceInternal::Incoming&, const Ice::Current&)':
test_exception_throwing.cpp:859: warning: exception of type `bla::XChild' will 
   be caught
test_exception_throwing.cpp:854: warning:    by earlier handler for `
   bla::Parent'
test_exception_throwing.cpp: In member function `IceInternal::DispatchStatus 
   bla::bli::___testi4(IceInternal::Incoming&, const Ice::Current&)':
test_exception_throwing.cpp:880: warning: exception of type `bla::XChild' will 
   be caught
test_exception_throwing.cpp:875: warning:    by earlier handler for `
   bla::Parent'
i think the exceptions are ordered alphabetically in the try{ } catch()... block generated by slice2cpp.

is this done deliberate?

the problem is that XChild will never be caught from a calling function because the exception will never be marshalled because all such exceptions will be interpreted as Parent

i think the order should be the same as given by the programmer.

in my example .ice code, this would mean that the methods testi1 and testi3 would give the warning, but it _would_ be possible to remove the warnings by manually reordering the exceptions.

with an alphabetical sorting, it is not possible to remove the warnings by reordering, the exceptions would have to be renamed.

edit: removed smilies in code

Last edited by peter.s : 03-25-2004 at 07:01 PM.
Reply With Quote
  #2 (permalink)  
Old 03-25-2004
mes's Avatar
mes mes is offline
ZeroC Staff
 
Name: Mark Spruiell
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Feb 2003
Location: California
Posts: 971
Re: Exception reordering in C++ interface

Quote:
Originally posted by peter.s
i think the exceptions are ordered alphabetically in the try{ } catch()... block generated by slice2cpp.

is this done deliberate?
No, this is simply an oversight on our part.

Quote:
the problem is that XChild will never be caught from a calling function because the exception will never be marshalled because all such exceptions will be interpreted as Parent
The caller will still receive the proper exception, because exceptions are marshaled using a virtual function. In other words, even if the exception handler for Parent is invoked, the caller will still receive XChild.

Quote:
i think the order should be the same as given by the programmer.
There are at least two ways we could handle this issue. One is to treat it as a coding style issue and formally recommend against (or have the translator prevent) declaring "duplicate" exceptions in an operation, where "duplicate" means the inclusion of base and derived exceptions. Technically, it's only necessary to list the base exception, since the operation is always allowed to raise derived exceptions without explicitly specifying each one. Of course, the receiver may not be able to unmarshal all of the derived exceptions, but that's a separate issue.

The other approach is to modify the code generator so that it avoids these warnings.

My colleagues and I will have to discuss this issue, and then I'll post the outcome.

Thanks,
- Mark
Reply With Quote
  #3 (permalink)  
Old 03-25-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
I'd be inclined to fix the code generator. Even though having both a base and a derived exception in an exception specification is pointless, I'd follow the precedent set by C++ and continue to allow this. We just need to make sure that the most-derived exception appear before any base exceptions in the catch blocks.

Cheers,

Michi.
Reply With Quote
  #4 (permalink)  
Old 03-25-2004
peter.s peter.s is offline
Registered User
 
 
Join Date: Mar 2004
Posts: 12
hm, fixing the code generator to honour the exception hierarchy would be one way to fix it, fixing it to hounor the programmers exception order would be the second way ....

personally, i think it's easier and perhaps more intuitively to keep the ordering as the programmer specified it - this way you don't need to go through the exception hierarchy tree too :-)

thanks for the fast answer :-)
Peter

edit: but automatic reordering would be more comfortable for sure :-)

Last edited by peter.s : 03-25-2004 at 07:14 PM.
Reply With Quote
  #5 (permalink)  
Old 03-25-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
Quote:
Originally posted by peter.s
hm, fixing the code generator to honour the exception hierarchy would be one way to fix it, fixing it to hounor the programmers exception order would be the second way ....

personally, i think it's easier and perhaps more intuitively to keep the ordering as the programmer specified it - this way you don't need to go through the exception hierarchy tree too :-)
Well, the order in which exceptions appear in an exception specification is irrelevant to the semantics of a method in both Java and C++, so I'd rather not attach semantics to the order for Slice excepton specifications.

Changing the code generator to arrange the catch blocks in most-derived to least-derived order is more work, but will fix the problem permanently, without the possibility of further surprises. (In general, any Slice specification that compiles must also generate correct code. Clearly, if we depend on the order chosen by the programmer, that wouldn't be the case.)

Cheers,

Michi.
Reply With Quote
  #6 (permalink)  
Old 03-26-2004
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
I've changed the parser to order the exceptions correctly.
You can pick up a patch in the Patches forum:

Patch for slice2cpp and slice2java

Cheers,

Michi.
Reply With Quote
  #7 (permalink)  
Old 03-26-2004
peter.s peter.s is offline
Registered User
 
 
Join Date: Mar 2004
Posts: 12
Talking

thank you very much, the patch works perfectly

Peter
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
Local interface mwilson Help Center 3 01-10-2007 12:22 PM
Have IceUtil::Exception inherit from std::exception? bpolivka Comments 2 12-13-2006 11:52 AM
std::string in interface dthompson Help Center 1 06-21-2006 05:49 PM
About Ice::Stats interface OrNot Comments 4 11-27-2005 09:32 PM
query for interface zanza Help Center 1 04-13-2005 08:34 AM


All times are GMT -4. The time now is 09:51 AM.


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.