|
|
|
|||||
|
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 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' 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. |
|
||||||
|
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. |
|
|||||
|
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. |
|
||||||
|
Quote:
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. |
|
||||||
|
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. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |