I'm having a debate with a co-worker about throwing exceptions from constructors, and thought I would like some feedback.
So to the point: In case, you wish that the dtor of your class will "take action" when you invoke it after (for this case) you catch the exception that your Although I have not worked C at a professional level, in my opinion, it is OK to throw exceptions from the constructors. All these forms are RAII; to resolve this, one must analyse RAII.This does not require you to initialize and connect everything on construction.In that case, you wouldn't want to use exceptions in your constructor any more than anywhere else, and you'd have to have an init method of some sort instead. Adding to all the answers here, I thought to mention, a very specific reason/scenario where you might want to prefer to throw the exception from the class's init method and not from the ctor (which off course is the preferred and more common approach). Should I rather create a member function init for the Mutex class and call pthread mutex_init within which would return a bool based on pthread mutex_init's return?This way I don't have to use exceptions for such a low level object.Something like this: Problem with this approach is on the caller side.Every user of the class would have to do an if before actually using the object.If in your case your initial state is mutex must be initialized then you should throw from the constructor.In contrast it is just fine not to initialize then ( as is done in The only time you would NOT throw exceptions from constructors is if your project has a rule against using exceptions (for instance, Google doesn't like exceptions).