Re: Bjarne's exception safe sample

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"George" wrote:

I agree with cd's comments. Maybe Bjarne means throwing exception through
operator new? Not sure his ideas -- hard to catch.

No, he means throwing an exception from T's copy constructor. You posted the quote yourself in original post:

-------
The assignment operator may fail by throwing an exception from T's copy constructor. This would leave a T in an undefined state because the old value of *p was destroyed and no new value replaced it.

-------

Alex

.



Relevant Pages

  • Re: DbC & Exceptions & Style
    ... exception. ... Different ways the constructor can fail ... to avoid writing code that converts GUI data into objects, ... All domain objects must now provide a default constructor. ...
    (comp.object)
  • Re: Controlled types and exception safety
    ... >> propagate an exception. ... >> For an Adjust invoked as part of an assignment operation, ... But a user-defined constructor is ... a user-defined constructor has just turned on the ...
    (comp.lang.ada)
  • Re: is such exception handling approach good?
    ... There is nothing wrong with throwing from constructor. ... It may be a good design, it may not be a good design from user's point ... resource API to free-up the resource on exception. ... change something - that is not initialization. ...
    (microsoft.public.vc.language)
  • Re: Question concerning object-oriented programming
    ... constructor the inspectof the state fails to verify key ... Better yet the constructor could throw an exception. ... opposed to stateless) object can know if it is in an invalid state. ...
    (comp.programming)
  • Re: Why does std::exception constructor specifies it can throw any ?
    ... > specifies that the constructors could throw any exception becuase they ... The constructor, copy constructor, operator=, ... DerivedException() throw ... contained objects don't throw. ...
    (comp.lang.cpp)