Results 1 to 5 of 5

Thread: General C++ exception not working with QT Necessitas

  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default General C++ exception not working with QT Necessitas

    Could someone tell me how to handle exceptions with a QT necessitas mobile app. I have Math app that throws an exception if something is divided by zero. The code works perfectly on QT SDK for windows but when I run the program on necessitas the app always crashes. Why can't I throw an exception? Remember this code works fine on QT SDK, when I use Necessitas QT SDK the app crashes.

    try
    {
    //Throw exception if divide by zero
    if ((terms[0] == 0) || (terms[3]== 0) || (terms[6] == 0) || ((terms[9]-terms[11])== 0 ) || ((terms[12]+terms[14])== 0 ))
    throw "Cannot divide by 0 term";


    this->answerline1->setText(QString::number(((terms[1]+terms[2])/terms[0])));
    this->answerline2->setText(QString::number(((terms[4]-terms[5])/terms[3])));
    this->answerline3->setText(QString::number(((terms[7]*terms[8])/terms[6])));
    this->answerline4->setText(QString::number((terms[10])/(terms[9]-terms[11])));
    this->answerline5->setText(QString::number((terms[13])/(terms[12]+terms[14])));
    }
    catch(const char * message)
    {
    cerr << "Error " << message << endl;
    }

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: General C++ exception not working with QT Necessitas

    I have also had trouble catching sigsegv (segmentation fault) exceptions (in Windows with Qt); the debugger reports something about exception handling via try/catch being incompatible with the signal / slot mechanism. As you are probably seeing, the catch clause is ignored even though the exception appears to be thrown, and the program crashes. In your case, simply replacing the try/catch with a conditional and a message box in case of error would solve your problem.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: General C++ exception not working with QT Necessitas

    See the other place you asked. Does that help?

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General C++ exception not working with QT Necessitas

    Quote Originally Posted by d_stranz View Post
    I have also had trouble catching sigsegv (segmentation fault) exceptions (in Windows with Qt); the debugger reports something about exception handling via try/catch being incompatible with the signal / slot mechanism. As you are probably seeing, the catch clause is ignored even though the exception appears to be thrown, and the program crashes. In your case, simply replacing the try/catch with a conditional and a message box in case of error would solve your problem.
    sigsev is not an exception that is thrown. It is your program going POP! You cant catch/recover from segfault.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: General C++ exception not working with QT Necessitas

    sigsev is not an exception that is thrown. It is your program going POP! You cant catch/recover from segfault.
    I oversimplified. What I actually did was to install a signal handler for sigsegv, and the handler threw an exception. The problem was that a third-party DLL over which I had no control (but which I had no choice except to use in my app) was blowing up with a segmentation fault. I needed to trap the fault, handle it, and let my app get on with life rather than dying a gory death. I could trap the signal just fine, but when I threw the exception out of it, Qt complained about that and the catch clause was never entered.

    It is possible that the DLL also garbaged up the stack in the process of the segmentation fault, which then resulted in the failure of the catch clause to run, but that's impossible for me to find out since I can't debug it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Qt Necessitas for Android
    By jeyanthinatarajan in forum Newbie
    Replies: 5
    Last Post: 22nd June 2012, 09:03
  2. Necessitas Android Help
    By RENOLD in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2012, 04:51
  3. Qt Necessitas - setFullScreen ?
    By leviribeiro in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 2nd November 2011, 22:56
  4. Necessitas Qt for Android issue
    By rickrvo in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 8th June 2011, 10:30
  5. Qt for Android. Necessitas
    By freely in forum Newbie
    Replies: 3
    Last Post: 27th May 2011, 18:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.