Just wanted to ask if there were commonly accepted solutions to the following problem:
typedef boost::error_info
f1_descr; and then
throw f1exception() << f1_descr("blah blah blah").
and later
catch(f1exception & ex){...}
The constructor of std::string may throw an exception in which case f1exception will never be thrown. This is not necessarily the desired outcome as the intention was obviously to indicate f1exception error, not the string() error.
This problem pertains to any type that throws exceptions in its constructor and is used with error_info idiom.
What may be more appropriate is something like this
typedef boost::error_info
f1_descr ... error condition is detected shared_ptr<string> pErrStr; try { pErrStr = new string("Error description"); } catch(bad_alloc & ex) { } throw f1exception() << f1_descr(pErrStr);
Meaning that if string fails to allocate memory, I'm willing to forgo the error description but still throw the intended exception.
Is there a cleaner way to do that?
Thanks, Andy.
I spoke with Emil about this at BoostCon. He understood and said that he would be looking at making this the default behavior. Jon