Archived

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

Exceptions and the ice_throw function

Why do Ice exceptions have an ice_throw method? And why is it sometimes used and sometimes not? I found that on Solaris using the Forte compiler the file UserExceptionFactorymanager.cpp fails to compile because the exception NotRegisteredException is thrown using the throw statement. Changing this to ex.ice_throw() makes it compile. Can someone please explain this to me? I think it is to do with the lack of a copy ctor on the exception class and the fact that ice_throw() is a const method. Have I found a bug in UserExceptionFactorymanager.cpp?

Regards,

Andrew

Comments

  • We have ice_throw() in order to be able to store exceptions, and throw them later.

    For example, sometimes you want to have a thread that sends requests in the background (a "call queue"). Any exceptions from sending such requests are stored and thrown when the main thread tries to add another request to the call queue.

    The code you are referring to is this:

    NotRegisteredException ex(__FILE__, __LINE__);
    ex.kindOfObject = "user exception factory";
    ex.id = id;
    throw ex;

    I don't see anything wrong with this code. An explicit copy constructor for NotRegisteredException is not necessary, because the constructor that the C++ compiler must create by default is perfectly ok for this.
  • Originally posted by marc
    NotRegisteredException ex(__FILE__, __LINE__);
    ex.kindOfObject = "user exception factory";
    ex.id = id;
    throw ex;

    I don't see anything wrong with this code. An explicit copy constructor for NotRegisteredException is not necessary, because the constructor that the C++ compiler must create by default is perfectly ok for this.

    In that case it looks like Forte requires an explicit copy ctor. Perhaps it shouldn't but it does.

    -apm