GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-May-2009, 20:29
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 67
rbp will become famous soon enough

How to crash gracefully


hello,

when a program like Firefox or Sketchup crashes we get a nice dialog saying what has happened. Some programs also give the option to send data from the crash to the developers.
How would I implement something like that for my own C++ app (on Windows)? Unfortunately I can not rely on exceptions because some of the libraries I use (eg Qt) don't use Exceptions.

Currently I have a program CrashHandler, which calls my main app in a new process. If my main app crashes, CrashHandler can detect it and inform the user.
However, when my main app crashes it brings up the standard Windows crash dialog alongside my own, which is confusing to the user. Is there a way around this? Or a better approach?

More importantly, how can I extract useful information from the crash to send to developers? On Linux I would use the GNU backtrace() method but I haven't found the equivalent on Windows.

cheers,
Richard
  #2  
Old 11-May-2009, 05:50
Mexican Bob's Avatar
Mexican Bob Mexican Bob is online now
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: How to crash gracefully


Why not simply write your programs so that they don't crash?

MxB
  #3  
Old 11-May-2009, 18:35
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 67
rbp will become famous soon enough

Re: How to crash gracefully


unfortunately even the best software teams release software with bugs. If you think you can, then either you haven't worked on a non-trivial project, or you are arrogant!

Read here:
http://www.codinghorror.com/blog/archives/001118.html


Anyone got any ideas?
  #4  
Old 11-May-2009, 23:23
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: How to crash gracefully


Quote:
Originally Posted by rbp
Unfortunately I can not rely on exceptions because some of the libraries I use (eg Qt) don't use Exceptions.
However, you can check all return values. And if later you realize that exception handling is useful, you can still wrap wherever the library calls are made with try-catch blocks & handle the errors appropriately.
  #5  
Old 12-May-2009, 07:00
Mexican Bob's Avatar
Mexican Bob Mexican Bob is online now
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: How to crash gracefully


Quote:
Originally Posted by rbp
unfortunately even the best software teams release software with bugs. If you think you can, then either you haven't worked on a non-trivial project, or you are arrogant!

Read here:
http://www.codinghorror.com/blog/archives/001118.html


Anyone got any ideas?

If you think that you "can't," you never will. Every winner is "arrogant," especially in the eyes of losers. If you never let failure become an acceptable option, you leave yourself no choice but to succeed. You may call that arrogant, I call it it determination. "There is no try, only do." Yoda.

I don't know why you think that a software team is "best" for releasing bugs, but you are welcomed to your opinion. However, if you keep telling yourself that "even the best software teams release software with bugs," someday you're going to believe it. The best software teams do not release bugs. Everybody else has done as much as they possibly can to promote the notion that they're still the best when they release buggy software. Maybe they did the best that they could given the situation and business case for the project, but that doesn't make them the best at anything.

Some software projects are not allowed to be released with bugs in them. Others are allowed by the businesses that release them. Some projects can't afford failures of any kind. Others believe that crashing a user's system is an acceptable risk and that minimizing that risk is useful for the business case when the cost of reducing that risk is acceptable to the business. Still other projects consider any crash of any kind to be unacceptable. I don't see how you get "best" from business cases that promote poor software quality.

The entire thinking that somehow exceptions (in C++) are some kind of programming elegance is foolhardy. They are very little more than interestingly applied goto statements. "That's not flying! That's falling with style." Woody.

I don't know which version of Qt you're using but:

Code:
-no-exceptions ..... Disable exceptions on compilers that support it. * -exceptions ........ Enable exceptions on compilers that support it.

...exceptions are enabled by default on my 4.5 commercial variety.

However, since you're asking for "ideas," I offer that you wrap your qapp.exec call in a C++ try block inside of your "main" code...even if exceptions are not enabled in your version of Qt. Then in your catch block, have your app that informs the user without alerting Windows of the crash.

BTW...I didn't follow your link. I've already seen enough "coding horrors" from teams who thought they were "the best." Don't get me wrong, I don't think that I'm the best either...but you won't find me "justifying" my failures by comparing them to the mistakes of others.

You never did answer my question:

Why not simply write your programs so that they don't crash?



MxB
  #6  
Old 12-May-2009, 09:07
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: How to crash gracefully


Quote:
Originally Posted by rbp
More importantly, how can I extract useful information from the crash to send to developers? On Linux I would use the GNU backtrace() method but I haven't found the equivalent on Windows.

I know you have a Windows-specific issue, but the approach may be the same...
When building on Linux you have to option to insert debug symbols so runtime evaluation by a debugger (gdb, for example) is more useful. Using those symbols and gdb command mode you can run an application through gdb and gather a backtrace if it fails (all of this hands-off).
If you can not do that, there is another approach using strace wherein you can spawn a process and register to receive all interrupts to system calls handled by your app, this includes some signal handling as well.

I point these out as I imagine that Windows has similar functionality and these may be a start for your search. In either case, though, there requires some 'under the hood' work to be done to understand these tools to their full capacity.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #7  
Old 12-May-2009, 09:08
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: How to crash gracefully


"If builders built buildings the way programmers wrote programs, the first woodpecker to come along could destroy civilization"
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #8  
Old 12-May-2009, 19:11
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 67
rbp will become famous soon enough

Re: How to crash gracefully


Quote:
Originally Posted by ocicat
However, you can check all return values. And if later you realize that exception handling is useful, you can still wrap wherever the library calls are made with try-catch blocks & handle the errors appropriately.

Checking return values is helpful, but we are interfacing with a lot of hardware (accelerometer, GPS, camera, etc) and some of these interfaces simply abort under bad conditions.
  #9  
Old 12-May-2009, 19:32
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 67
rbp will become famous soon enough

Re: How to crash gracefully


Quote:
Originally Posted by Mexican Bob
Why not simply write your programs so that they don't crash?

Even if we could write bug free code, we are relying on libraries from third party vendors, which are excellent but buggy. For example look at the bug list from the last minor release for Qt: http://www.qtsoftware.com/developer/...changes-4.5.1/


Quote:
Originally Posted by Mexican Bob
The best software teams do not release bugs.
I'd be extremely interested if you could point me to a non trivial project that was released with no bugs.
I'm sure the engineers at Google, Nokia, etc would also be interested, because they also can't help releasing buggy software!
  #10  
Old 12-May-2009, 20:01
rbp rbp is offline
Junior Member
 
Join Date: Nov 2005
Location: Melbourne, Australia
Posts: 67
rbp will become famous soon enough

Re: How to crash gracefully


I found the following windows function that may provide the debugging information:
http://msdn.microsoft.com/en-us/library/ms680360.aspx

And to stop the windows crash dialog we now intercept abort signals and then exit manually.

Together this should help us diagnose problems if our program crashes remotely.
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard Disk Crash petter.smith0 Computer Hardware Forum 0 23-Jan-2008 02:22
runtime crash? can somebody explain to me why this happen swedenguy C Programming Language 4 17-Aug-2006 11:15
Firefox crash fhj52 GIDForums™ 2 05-Jul-2006 12:02
What are hotspot crash? jaro Java Forum 0 18-May-2006 08:17
FLTK2 setting input value of an FLTK Input field causes system to crash. Gutty FLTK Forum 0 06-Apr-2005 14:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:22.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.