[omniORB] SystemException::NP_minorString() returns 0

Rene Jager renej_frog at users.sourceforge.net
Sun Sep 26 03:06:18 BST 2004


On Sun, 2004-09-26 at 00:56, Alex Tingle wrote:
> I wrote:
> > > I expect to have to test the result of a call when it returns
> > > `char*', but I'd usually expect functions that return `const char*'
> > > to always give me something I can use.
> 
> Rene Jager <renej_frog at users.sourceforge.net> wrote:
> > I'd prefer a string with the minor code instead of "unknown". These
> > things can be done easily with small inline functions (as I do now).
> > That way you can also hide the use of NP_* functions.
> 
> Hmm. This is hard to do. The function returns `const char*', so the
> caller would not expect to be responsible for freeing the return value's
> memory. That makes it difficult to manufacture descriptive strings on
> the fly.

I know, that's why I use a small function to do that

> 
> You can easily overcome this problem by returning a class (like
> std::string), but then you're adding to the complexity (if you write
> your own class) or depenencies (if you use the STL).

sure, but I'm so lucky that using std c++, stl and boost is no problem,
so

    std::string getMinorCodeStr(CORBA::SystemException const& ex)
    {
        char const* s = ex.NP_minorString();
        if (s)
            return s;
        else
            return boost::lexical_cast<std::string>(ex.minor());
    }

is possible

> 
> > Returning not a 0 ptr would make it harder to detect for the prgrammer
> > that it is an unknown minor code.
> 
> That's just not true. An empty string is just as easy to test for:
> 
>   if(minor[0])...
>   if(::strlen(minor)==0)...

you're right if it's a "" string, but I was thinking about your
suggestion "unknown minor string" since you gave an example using the
returned string directly in printing or alike

> 
> In any case, this accessor method is the wrong place for testing whether
> a code is known. A special `bool NP_hasRecognisedMinorCode()' method
> would be more appropriate.

but that would require 2 look-up's; OTOH, costs ignorable wrt catching
and handling exceptions

renej
-- 




More information about the omniORB-list mailing list