Results 1 to 8 of 8

Thread: Crash gracefully?

  1. #1
    Join Date
    Aug 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Crash gracefully?

    Hello,

    I'm looking for a (cross platform) way of catching various crashes (double free, referencing invalid memory, division by zero, etc...) so that I can log them.

    Currently I have my own message handler installed to catch standard Qt messages (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg). This handler pushes the messages to stderr, but also logs them to a log file.

    My hope is I can also catch non Qt errors and send them through the same message handler. The thing is I'm not sure of the correct way to do this (if there even is a correct way).

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash gracefully?

    On Windows you need to install an exception frame.

    I don't know about Linux.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Crash gracefully?

    Invalid memory exceptions are not defined by the C++ specification; they are provided by some compilers and environments, but this is platform dependent. The best way to deal with them is through thorough testing that eliminates such access attempts, ensuring that they will never occur during runtime

    The same is true for division by zero - there aren't any defined runtime exceptions thrown - but this is very easy to check yourself at runtime simpy by checking the divisor.

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Crash gracefully?

    Well, nice question (i think)

    But the answer isn't so nice (simple)
    The proper usage of OOP principles is the portable "way" of preventing most of the things that you enumerated, so encapsulate dynamic allocated memory in class, allocate in constructor, delete in destructor)

    Or maybe <if necessary> use some smart pointers solve some of that problems
    PS: the link is to boost libraries (just for exemplification of concept, Qt must have at least some of them)

    LE: i think that you must concentrate on not to crash (or very rare crash) not on "beautiful crashes", so coding the right way usually saves you from that.
    Last edited by Zlatomir; 3rd July 2010 at 19:19.

  5. #5
    Join Date
    Jun 2010
    Location
    India
    Posts
    50
    Thanks
    1
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crash gracefully?

    Hi,

    Signal handlers may help....~! and it may work in both OS(Linux & Windows)


  6. The following user says thank you to agathiyaa for this useful post:

    ultim8 (6th July 2010)

  7. #6
    Join Date
    Aug 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crash gracefully?

    All:

    Yes, the correct thing to do is make it so your application never crashes via regression testing, unit tests, alpha/beta testing.... and of coarse smart coding. But the truth of the matter is, it can and DOES happen. If and when it does happen, I want a log of it so I can more easily find the issue and fix it.

    Agathiyaa:

    Yes, I actually ran into Signal Handlers on Wikipedia shortly after posting my original post. I haven't had time to look too deeply into them, but they look promising. They are part of the C standard too, so should be compatible cross platform. I'll post more once I try them out.

  8. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash gracefully?

    Instead of rolling your own, maybe you could use one of the pre-existing exception handlers and concentrate your efforts and getting your app bug free

    There are lots of different ones which you just bolt to your app once you have something that works. They log all the info they can, some will try and email you the results, etc.

  9. The following user says thank you to squidge for this useful post:

    Zlatomir (6th July 2010)

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

Similar Threads

  1. QwtPlot crash in Mac OS X
    By sirmojtaba in forum Qwt
    Replies: 2
    Last Post: 21st August 2009, 02:28
  2. Replies: 4
    Last Post: 14th May 2009, 00:43
  3. How to crash gracefully
    By rbp in forum Qt Programming
    Replies: 22
    Last Post: 8th May 2009, 08:54
  4. Crash detection
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 12:09
  5. Crash in QTableWidget
    By ghorwin in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2007, 16:57

Tags for this Thread

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.