I'm writing a reusable class. The constructor (declared explicit) makes several checks on the std::string passed as an argument.
In case of a malformed string it throws an exception. Several errors are possible and each provides its own throw. The throws are using the standard library objects declared in stdexcept.
After all checks are done, it then proceeds to fill in some of its data members.
The whole error checking section is contained inside a try-catch block.
The catch blocks simply output the error message through std::cerr and then... I call terminate().
And this is what is worrying me, as this means any constructors for any objects created so far on the code (some of which could be dynamically allocated objects of other types) exit abnormally without their destructors being called. Using my class would mean that during the coding and testing process, a programmer could be faced with innumerous memory leaks.
How should I approach this? Should I simply throw and expect the class user to set try-catch blocks on their code (If I still want to output the error message I can simply cerr it and rethrow)?
On the event I want to actually exit on the constructor, how can I output the error message, and terminate the program safely?