title: Exception elimination in C++ constructors
body: <p>We have recently been faced with the problem of porting our C++ framework to an ARM platform running uClinux where the only vendor supported compiler is GCC 2.95.3. The problem we have run into is that exceptions are extremely unreliable causing everything from not being caught at all to being caught by an unrelated thread(!). This seems to be a documented bug, i.e. <a href="http://gcc.gnu.org/ml/gcc/2003-08/msg01013.html" rel="noreferrer">here</a> and <a href="http://osdir.com/ml/lib.uclibc.general/2003-05/msg00121.html" rel="noreferrer">here</a>.</p>
  
  <p>After some deliberation we decided to eliminate exceptions altoghether as we have reached a point where exceptions do a lot of damage to running applications. The main concern now is how to manage cases where a constructor failed.</p>
  
  <p>We have tried <a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;seqNum=264" rel="noreferrer">lazy evaluation</a>, where each method has the ability to instantiate dynamic resources and return a status value but that means that every class method has to return a return value which makes for a <strong>lot</strong> of ifs in the code and is very annoying in methods which generally would never cause an error.</p>
  
  <p>We looked into adding a static <em>create</em> method which returns a pointer to a created object or NULL if creation failed but that means we cannot store objects on the stack anymore, and there is still need to pass in a reference to a status value if you want to act on the actual error.</p>
  
  <p>According to Google's C++ Style Guide they <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Exceptions" rel="noreferrer">do not use exceptions</a> and only do trivial work in their constructors, using an init method for non-trivial work (<a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Doing_Work_in_Constructors" rel="noreferrer">Doing Work in Constructors</a>). I cannot however find anything about how they handle construction errors when using this approach.</p>
  
  <p>Has anyone here tried eliminating exceptions and come up with a good solution to handling construction failure?</p>