Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:47:52+00:00 2026-06-10T16:47:52+00:00

I use CMake to create my projects. In the project I use mainly Qt

  • 0

I use CMake to create my projects. In the project I use mainly Qt C++ and some MFC functions for hardware interface. Does it make any sense to use try/catch e->ReportError() or some other exception statements in the code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:47:53+00:00Added an answer on June 10, 2026 at 4:47 pm

    You can of course use exceptions together with Qt. The question is just, how useful they are. As an example, consider the following class

    class Thrower : public QObject
    {
        Q_OBJECT
    public slots:
        void throwException()
        {
            throw 42;
        }
    };
    

    The exception is thrown inside a slot. To catch this exception, you have to wrap the
    signal, which triggers the slot, in a try block, e.g.

    class Catcher : public QObject
    {
        Q_OBJECT
    public:
        Catcher(Thrower* t)
        {
            connect(this, SIGNAL(test()), t, SLOT(throwException()));
        }
    
        void catchTest()
        {
            try
            {
                emit test(); // Will trigger Thrower::throwException().
            }
            catch (int number)
            {
                qDebug() << "Caught" << number;
            }
        }
    
    signals:
        void test();
    };
    

    Unfortunately, it is not always possible to use this approach. For example, when you connect QPushButton::clicked() to Thrower::throwException(), clicking the button
    will cause a crash of the event loop.

    You could wrap QApplication::exec() in a try-block, but when you catch the exception, the GUI is most likely already destructed, so there is no real possibility to recover from an exception.

    Also have a look at the Qt documention about exception safety.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I use something like this to create project make files: cmake -DCMAKE_INSTALL_PREFIX=./install-dir -DBUILD_WITH_STATIC_CRT=ON
I use CMake to create build scripts (Makefiles + VS solutions) for my projects.
I'm just found cmake and I want to use it to create make files
I use some libraries that I don't want built as part of every project
i have written a library with some classes that make use of qt object
I'm trying to get rid of cmake in my project for some reasons. I
I use CMake to manage a project with the following layout: ProjectA/ include doc
I'm using cmake with C++ project. I want to use precompiled headers in GCC.
I've just started using CMake for some personal and school projects, and I've been
I've created the eclipse project with cmake. I use vtk with qt. Dir structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.