Please tell me how to use try/catch properly with boost::exception.
This is one of examples
void Settings::init(const std::string &filename)
{
using boost::property_tree::ptree;
try
{
read_xml(filename, pt);
}
catch(boost::exception const& ex)
{
LOG_FATAL("Can't init settings. %s", /* here is the question */);
}
}
Do I need catch std::exception too?
I can’t let my application fail, so I just need to log everything.
UPD:
I also can’t understand now to retrive information for logging from exception???
std::exceptionhas a member function calledwhat()that returns aconst char*that might explain what happened. If you want to log it (guessing thatLOG_FATALwrapsprintfsomehow) you can do:For
boost::exceptionthough you can useboost::get_error_infoto find out more about it.