Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Try & Catch in QApplication
Forum Updated to NodeBB v4.3 + New Features

Try & Catch in QApplication

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 8.4k 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.
  • R Offline
    R Offline
    rikytres
    wrote on last edited by
    #1

    I try to manage the exception of my classes, and i put this "Throw" in the constructor.
    @
    line::line(point A, point B):a(A), b(B){
    if (a==b) {throw coincidentPointLine();}
    }
    @
    This is in the logical part of the my project and there's no Qt object of function in this class.

    And this is a slot of my QMainWindow:
    @void mainWindow::on_twoPointLineButton_clicked(){
    //get the input line
    QString Qinput = ui->lineEdit->text();
    std::string input = Qinput.toStdString();

    line* L;
    try{L = new line(GUIUtilities::getInputLine(input));}
    catch (coincidentPointLine()){
        std::cout<<"error";
        this->setResult(QString("Error Message!"));
        abort();}
    
    function F = L->lineEquatioon();
    std::string result = F.get[removed]);
    this->setResult(result);
    

    }@

    It's look like it woks but doesn't! The compiler return this error!
    Qt has caught an exception thrown from an event handler. Throwing
    exceptions from an event handler is not supported in Qt. You must
    reimplement QApplication::notify() and catch all exceptions there.

    How i can resolve this problem?
    I read about QApplication::notify(), but i don't understand very well...

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on last edited by
      #2

      "this ":http://qt-project.org/forums/viewthread/2343 and "this":http://doc.qt.nokia.com/4.7-snapshot/exceptionsafety.html

      must be useful..


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rikytres
        wrote on last edited by
        #3

        Thanks! ;)

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          You better change your code to not throw from the constructor. How do you reclaim the memory used by a object that threw in its constructor? It is not constructed yet, so there is no object. There is nothing you can call the destructor on.

          See e.g. http://herbsutter.com/2008/07/25/constructor-exceptions-in-c-c-and-java/

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Duck
            wrote on last edited by
            #5

            Your problem has nothing to do with Qt.

            "catch (coincidentPointLine())" catches exceptions of type function-without-parameters-returning-coincidentPointLine. You are throwing objects of type coincidentPointLine. The types are unrelated.

            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