Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Using QtConcurrent::Exception with boost::exception
Forum Updated to NodeBB v4.3 + New Features

Using QtConcurrent::Exception with boost::exception

Scheduled Pinned Locked Moved C++ Gurus
1 Posts 1 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zethon
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved