Re: is such exception handling approach good?



it is normally not a good idea to do operations in the ctor that could
cause an exception. the reason for this is that if an exception is
ever thrown in your ctor you end up with an invalid object. therefore
it is better to have some other method to initialize such with and
handle a failure outside the ctor like bool init() or something.

That's completely false as Alex stated.


.



Relevant Pages

  • Re: Exception handling?
    ... Maybe with FP, exception trapping could now be considered even more important because in classic FP, its not something you think about, you can't if you wish to stack commands which is also the same idea with OOPS based protocol stacking. ... accept "If this function returns TRUE, then the CString & contains the result, but if this ... But I never really understood why a FP approach was not a big consideration for construction: ... With two-step construction you don't need to throw exception in ctor, because the default ctor just puts the object in a safe state and the actual construction is done in a /ad hoc/ construction method, Create...). ...
    (microsoft.public.vc.mfc)
  • Re: is such exception handling approach good?
    ... the reason for this is that if an exception is ... ever thrown in your ctor you end up with an invalid object. ... handle a failure outside the ctor like bool initor something. ...
    (microsoft.public.vc.language)
  • Re: is such exception handling approach good?
    ... the reason for this is that if an exception is ... ever thrown in your ctor you end up with an invalid object. ... handle a failure outside the ctor like bool initor something. ...
    (microsoft.public.vc.language)
  • Re: is such exception handling approach good?
    ... same time, the construction of m_Whatever is successful, but the construction ... of current instance is failed and exception is thrown -- throw ... if the caller of the constructor MyClass() is smart enough, ... handle a failure outside the ctor like bool initor something. ...
    (microsoft.public.vc.language)
  • Re: is such exception handling approach good?
    ... cause an exception. ... ever thrown in your ctor you end up with an invalid ... There is nothing wrong with throwing from constructor. ... won't end up with invalid object. ...
    (microsoft.public.vc.language)