Archived

This forum has been archived. Please start a new discussion on GitHub.

Question about slice and exception.

hi, there,
1) I have the fellowing ice definition:

class Server;
sequence<Server> ChildServers;
class Server
{
string address;
string name;
ChildServers childServers;
};

An error occured when compiled to cpp:
`childServers' has changed meaning

I can't figure out what was wrong.

2) if client can catch a system excetpion thrown by server . I mean, that exception is not anticipated in advance and thrown by a derived exception from userException.


Thanks alot.

OrNot

Comments

  • matthew
    matthew NL, Canada
    The first error is caused by the variable only differring in case with an existing identifier. This is not legal slice. From the Ice manual:
    Case Sensitivity

    Identifiers are case-insensitive but must be capitalized consistently. For example, TimeOfDay and TIMEOFDAY are considered the same identifier within a naming scope. However, Slice enforces consistent capitalization. After you have introduced an identifier, you must capitalize it consistently throughout; otherwise, the compiler will reject it as illegal. This rule exists to permit mappings of Slice to languages that ignore case in identifiers as well as to languages that treat differently capitalized identifiers as distinct.

    As to the second question any unexpected user exception can be caught as UnknownUserException.
  • Thank you Matthew.
  • hi,
    Another question about exception:

    In c#, the userException is showed as the following:

    public abstract class UserException : Exception
    {
    public UserException() {}
    public UserException(string msg) : base(msg) {}
    public UserException(System.Exception ex) : base(_dflt, ex) {}
    public UserException(string msg, System.Exception ex) : base(msg, ex) {}
    .........
    }

    Howerver, in java, the userException has no constructors as those in cs.


    I just feel curious about what your considerations were here. The reason why I asked this quesiton is that it is not very convenient when I want to create a new exception by means of the construtors as in c#.


    Thanks in advance.
    OrNot
  • In C#, exceptions are mapped they way they are because of the .NET framework, which recommends that applications should derive their exceptions from System.ApplicationException. Ice.Exception derives from that base class, and the constructors are simply the constructors that are present on System.ApplicationExceptions, so you can add a message to an exception, as well as an inner exception. (These members are printed by the toString() method of ApplicationException.)

    For Java, no such base class convention exists, so you just get a plain default constructor in Java.

    In the next release of Ice, Java (but not C#) will have a "one-shot" constructor for exceptions as well as a default constructor, so you can instantiate and initialize an exception in a single statement (instead of having to assign to the exception members after instantiating the exception). This will make Java exceptions a little easier to use.

    For C#, we don't provide "one-shot" constructors because they create a conflict for exceptions with a single string member:
    // Slice
    exception E { string s; };
    
    // C#
    public class E : Ice.UserExcption
    {
        public E(string s) // Which constructor would this be, the one for E or the one for UserException?
    };
    

    Cheers,

    Michi.
  • hi,michi,
    What's the defference between the "ConnectionTimeoutException" and the
    "ConnectTimeoutException"? From the doc, they seem to have the same meanings.

    Best Regards
    OrNot
  • bernard
    bernard Jupiter, FL
    ConnectTimeoutException is for the connection establishment; you get ConnectionTimeoutException once the connection is established, for example if you don't get a reply to your request within the timeout associated with the connection.

    A quick search through the doc shows a couple mix-ups ... we will fix them!

    Cheers,
    Bernard