Using QtConcurrent::Exception with boost::exception
-
I want to use an exception hierarchy where the base exception class derives from boost::exception so that I can get the nice and useful diagnostic information that that class has to offer and QtConcurrent::Exception so that I can throw my exceptions across threads.
Hence, my base exception class looks like:
@class MyException : public QtConcurrent::Exception, public boost::exception
{
public:
MyException() { };
virtual ~MyException() throw() { }// required by QtConcurrent::Exception to be implemented virtual void raise() const { throw *this; } virtual MyException* clone() const { return new MyException(*this); }
};@
Per QtConcurrent::Exception's documentation, raise() and clone() must be implemented in any class derived from QtConcurrent::Exception. So, the rest of my code may look something like:
@void foo()
{
BOOST_THROW_EXCEPTION(MyException());
}int main(int argc, char *argv[])
{
QApplication app(argc, argv);try { foo(); } catch (const MyException& me) { std::cerr << boost::diagnostic_information(me); } return 0;
}@
However, using the BOOST_THROW_EXCEPTION() macro causes the following compilation error:
bq. error C2555: 'boost::exception_detail::clone_impl::clone': overriding virtual function return type differs and is not covariant from 'MyException::clone'
I am not entirely sure what this error is telling me (my fault, not the errors, I'm sure!).
If I instead use throw MyException(); the code compiles just fine. As I mentioned above, I'd like to use BOOST_THROW_EXCEPTION() so that I get the diagnostic information in my exceptions.
I know that one possible work-around could be another class derived from just QtConcurrent::Exception that has a boost::exception member, essentially a container for the actual error. But if possible, I would like to continue to have the MyException class inherit from both QtConcurrent::Exception and boost::exception.
Can someone offer some insight into what the error is saying? Is there any way to accomplish what I want?