Search This Blog

Friday, May 13, 2011

ExceptionalC++ Fun: 8. Exception Safe code (destructor and constructor)

  • in most cases, do not throw in the destructor. let the destroctor finishes its job.
  • have a nice default constructor; if something is wrong, the object is not even constructed. you don't have to worry about the object state. it's not even exists yet, and all internal stuff are clean out by destructor(s).
a nice style:

  : v_(new T[10]),  // default allocation
    vused_(0)       // nothing used yet

No comments: