Home Help Center

'local' user exceptions possible?

kpflemingkpfleming Member Kevin P. FlemingOrganization: Digium, Inc.Project: Asterisk SCF
I suspect this doesn't qualify as a bug, so I'm posting it here instead of the bug forum.

In our project, we're using Slice to define a set of interfaces for some functionality that will only exist locally (no remote interaction at all), similar to what Ice itself does for Icebox and other services that can be used from an application/component. In this case, Slice is our 'IDL', and we'll build implementations of this functionality in various languages, and consuming developers will have a consistent interface to these mechanisms.

Now on to the actual problem: in some of our interfaces, we'd like some of the operations to be able to throw exceptions... so we defined them in the Slice file. If the exceptions are defined as 'normal' (not defined as 'local'), the generated C++ code compiles properly, but the exceptions cannot contain 'local' objects (which we want to do to indicate to the caller which specific objects caused the exception to be thrown). If we define the exceptions as 'local', they can contain local objects, but they derive from Ice::LocalException which appears to be for Ice run-time usage only... and worse, the exception declarations include an ice_print() virtual member function, but there is no definition of that function provided.

I fear that once again we're trying to use Slice in a way that wasn't anticipated... is there a way to do what we want to do?

Comments

  • kpflemingkpfleming Member Kevin P. FlemingOrganization: Digium, Inc.Project: Asterisk SCF
    Oh, I forgot the details asked for above... we are using Ice 3.4.1, translating Slice to C++, and compiling with GCC 4.4.x on Linux.
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Kevin,

    If your exception contains local objects, it should be declared as 'local'. This question probably didn't come up before because using local types is unusual.

    In C++ (and only in C++), the generated code for local exceptions declares a function ice_print, but does not generate its implementation. This allows the developer (so far mostly us) to provide an implementation that prints a better error message, using the data members of the exception.

    Unfortunately this behavior is neither optional nor documented... so it's a bug. It would be cleaner to make this feature optional and triggered by metadata, something like:
    ["cpp:overwrite_ice_print"]  // C++ generated code will declare ice_print,
                                          // but won't provide its implementation
    local exception MyLocalError
    {
    };
    

    Would this work well for you?

    Thanks,
    Bernard
  • kpflemingkpfleming Member Kevin P. FlemingOrganization: Digium, Inc.Project: Asterisk SCF
    Yes, making the 'ice_print' generation optional would definitely solve the problem.
Sign In or Register to comment.