how to override std::exception::what() for Ice::UserException?

evgkevgk Member Evgeny KlunkoOrganization: ISTP SB RASProject: telescope control system
Hi,

The code structure of my client application is as follows:
int main() {
   try {
      ...
      proxy->my_method(1234);
      ...
   }
   catch(const std::exception& e) {
      cerr << "main: std::exception: " << e.what() << endl;
   }
}
I catch std::exception because my own exceptions hierarchy is based on it.

And I'd like my user exceptions (derived from Ice::UserException) to be more talkative, e.g.
// on server side, inside implementation of my_method
stringstream s;
s << "my_method: bad argument: " << arg << endl;
throw MyUserException(s.str());

So is it possible to override std::exception::what() method for exception classes that are derived from Ice::UserException?

Thank you in advance,
Evgeny

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Evgeny,

    It's not possible: Ice does not allow you to customize generated C++ exceptions (or generated C++ structs) - you cannot register your own implementation of "MyUserException" and tell Ice to use it instead of the generated MyUserException.

    Best regards,
    Bernard
  • evgkevgk Member Evgeny KlunkoOrganization: ISTP SB RASProject: telescope control system
    Possible it would be not a bad idea to implement (inside Ice) another exception with following properties:
    - derived from UserException
    - receive string argument on instantiation
    - override std::exception::what() member to print that string argument
Sign In or Register to comment.