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:


template
Stack::Stack()
  : v_(new T[10]),  // default allocation
    vsize_(10),
    vused_(0)       // nothing used yet
{
} 

No comments: