Results 1 to 20 of 23

Thread: How to crash gracefully

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation How to crash gracefully

    hi,

    when a program like Firefox or Sketchup crashes we get a nice Dialog saying what has happened.
    How would I implement something like that for my own Qt app?

    I naively tried this:
    Qt Code:
    1. try {
    2. app.exec();
    3. }
    4. catch(...) {
    5. // launch crash dialog
    6. }
    To copy to clipboard, switch view to plain text mode 
    which does not work because Qt does not use exceptions.

    Is there a platform independent solution to make my app crash gracefully? Or do I need to look into signals on Linux, etc.

    Richard

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    I usually use a slot fatalError(const QString&) in program's Main Window and connect this with children's signal fatalError(const QString&).

    The code of MainWindow::fatalError can be:
    Qt Code:
    1. void MainWindow::fatalError(const QString& _details)
    2. {
    3. QMessageBox::Critical,
    4. tr("Fatal Error"),
    5. tr("%1 has encountered an error and cannot continue to work.\n"
    6. "Please press OK button to quit.").arg(qApp->applicationName()),
    7. this);
    8.  
    9. mbox.setDetailedText(_details);
    10.  
    11. mbox.exec();
    12. qApp->quit();
    13. }
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    how do the child widgets know when to emit fatalError()?

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    You can catch failure conditions and emit fatalError
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    that seems to be back to my original problem, except with the child widgets instead of the main window. I have found I can't catch errors because Qt doesn't use exceptions.

    How do you catch all errors for a widget?

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    Sorry, but I don't understand the question!

    Qt don't use exceptions for signaling errors but each method returns a value (typically a boolean) that indicates the result of the executed operations.

    You can test this value and emit the fatalError signal.

    If you give some examples, I can help you.
    A camel can go 14 days without drink,
    I can't!!!

  7. #7
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to crash gracefully

    ah OK, yeah I already handle those kind of anticipated errors.

    What I'm aiming at is handling unexpected errors - even a great app like Firefox crashes unexpectantly sometimes. See here.
    If/when my app crashes I want them to send debugging information to a central server. But so far I haven't figured out how to 'catch' the crash.

  8. #8
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to crash gracefully

    Don't think you can find any help from here on this issue, see this:
    http://www.qtcentre.org/forum/f-qt-p...xit-20172.html

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to crash gracefully

    Quote Originally Posted by rbp View Post
    If/when my app crashes I want them to send debugging information to a central server. But so far I haven't figured out how to 'catch' the crash.
    If your application crashes, you have to be prepared for the crash - you have to expect it to crash in a particular place. Crash is either an unhandled exception that you can catch (Qt doesn't throw exceptions but it doesn't prevent exceptions to be thrown from other classes/functions) or a situation when you violate an OS policy and your application gets terminated. If the crash happens in your code, you can use exceptions and do some cleanup. If the crash happens unexpectedly then using GUI (or network) is probably unsafe anyway as I said in the thread quoted by Ini.

    If you force firefox to sigsegv, it won't close gracefully, it will just be terminated. The feedback thingy is probably an external application that gets executed when a crash occurs and that you can do with your application as well upon a sigsegv. But it won't give you much meaningful information (except a backtrace).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to crash gracefully

    Quote Originally Posted by wysota View Post
    If your application crashes, you have to be prepared for the crash - you have to expect it to crash in a particular place. Crash is either an unhandled exception that you can catch (Qt doesn't throw exceptions but it doesn't prevent exceptions to be thrown from other classes/functions) or a situation when you violate an OS policy and your application gets terminated. If the crash happens in your code, you can use exceptions and do some cleanup. If the crash happens unexpectedly then using GUI (or network) is probably unsafe anyway as I said in the thread quoted by Ini.

    If you force firefox to sigsegv, it won't close gracefully, it will just be terminated. The feedback thingy is probably an external application that gets executed when a crash occurs and that you can do with your application as well upon a sigsegv. But it won't give you much meaningful information (except a backtrace).
    see this: http://www.slb.com/media/services/so...dk/CSL_Exc.pdf

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to crash gracefully

    Quote Originally Posted by lni View Post
    I'm not sure what point are you trying to give by referring that document. C++ has its own exception system which seems a bit more advanced than that of CSL (still crappy though). And by the way, SIGSEGV and SIGBUS are not exceptions (they are much more serious than exceptions, they are "generated" by the operating system), let's not mix the concepts (it's as if we said C was an object oriented language because it supported structures).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to crash gracefully

    Quote Originally Posted by wysota View Post
    I'm not sure what point are you trying to give by referring that document. C++ has its own exception system which seems a bit more advanced than that of CSL (still crappy though). And by the way, SIGSEGV and SIGBUS are not exceptions (they are much more serious than exceptions, they are "generated" by the operating system), let's not mix the concepts (it's as if we said C was an object oriented language because it supported structures).
    You may be right that CSL is crappy. But that codes work. That is probably one of the reasons that Schlumberger software has had much better sale than most other competitors.

    The concept is easy to understand, when an exception or signal is raised, the signal handler catch and throw an exception, and event handler process the exception and never let the exception handler return out of the function. If the exception handler return from the function, it will go back to where it crashes, which will trigger exception handler again, causing a dead loop.

    So the idea is to throw out of the crash point, and let the program return back to the normal event loop, the problem is then solved... Schlumberger can do it, I think Qt can do it too...

    Let's not talk about SEGV, let's do "man abort", and see what is said: "The abort() function shall cause abnormal process termination to occur, unless the signal SIGABRT is being caught and the signal handler does not return". I just don't know how to do it in Qt...Perhaps you know it...

    There is no example on Qt for this: http://doc.trolltech.com/main-snapsh...x-signals.html

Similar Threads

  1. Crash: Heap corruption due to selectedRows()
    By Ankitha Varsha in forum Qt Programming
    Replies: 16
    Last Post: 1st October 2010, 00:55
  2. Replies: 28
    Last Post: 9th March 2010, 08:59
  3. Qwt crash in Vista
    By roland8454 in forum Qwt
    Replies: 3
    Last Post: 3rd February 2009, 19:53
  4. Replies: 2
    Last Post: 13th August 2008, 17:46
  5. QTimer ->start(0) + OpenGL + resize/move window => crash
    By anthibug in forum Qt Programming
    Replies: 5
    Last Post: 8th July 2008, 11:01

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.