I have a custom exception class that inherits from boost::exception as follows:
class ConfigurationException : public boost::exception
{
public:
ConfigurationException(const std::string & title, const std::string & message) {
QMessageBox box(QMessageBox::Critical, QString::fromStdString(title), QString::fromStdString( parse(message) ), QMessageBox::Ok);
box.exec();
}
}
and it can be called from code like this:
try {
// Do some stuff here
} catch (std::exception e) {
BOOST_THROW_EXCEPTION( ConfigurationException("Configuration Error", e.what()) );
}
However, when I try to compile, I get the errors
Libs\boost\include\boost/throw_exception.hpp(58): error C2664:'boost::throw_exception_assert_compatibility' : cannot convert parameter 1 from 'const ConfigurationException' to 'const std::exception &'
Reason: cannot convert from 'const ConfigurationException' to 'const std::exception'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Libs\boost\include\boost/throw_exception.hpp(85) : see reference to function template instantiation 'void boost::throw_exception<E>(const E &)' being compiled
with
[
E=ConfigurationException
]
src\ConfigurationReader.cpp(81) : see reference to function template instantiation 'void boost::exception_detail::throw_exception_<ConfigurationException>(const E &,const char *,const char *,int)' being compiled
with
[
E=ConfigurationException
]
I’m not really sure why it’s trying to cast my exception to an std::exception. Can someone tell me how I can throw this exception and get the file, function etc. data too? (I should say obviously that throw ConfigurationException("some title", "some message"); works fine.
std::exceptionandboost::exceptionvirtually:struct ConfigurationException : virtual std::exception, virtual boost::exception.catch (const std::exception& e).catchblock).error_infoto attach additional information (like your title and message).And in general, be careful when mixing Qt with exceptions.