Archived

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

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

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

  • bernard
    bernard Jupiter, FL
    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
  • 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