Chapter 13: Crash Handlers


Overview

This news flash shouldn't come as a shock, but I'm going to let you in on a little secret: your users really hate seeing that Application Error or error report dialog box pop up when your application crashes. The fact that you're reading this book means that you're trying hard to avoid crashes in the first place. As we all know, however, crashes happen even in the best applications, and you need to be prepared for them.

Instead of just letting the Application Error dialog box make an appearance and irritate your users, wouldn't it be nice if a user-friendly dialog box popped up and reported the problem, and asked the users exactly what they were doing at the time of the crash? Wouldn't it be even better if, in addition to recording the usual crash address and call stack that utilities such as Dr. Watson give you, this kinder and gentler dialog box recorded the internal state of your program so that you could get the processing and data states at the time of the crash? And wouldn't it just be icing on the cake if the dialog box automatically e-mailed the crash information to you and logged a bug report directly into your bug tracking system?

Crash handlers can turn such wishful thinking into reality, providing you with all the cool information I fantasized about in the preceding paragraph. Crash handlers is the term I've come up with to describe both exception handlers and unhandled exception filters. If you've done any C++ programming, you should be familiar with exception handlers. You might know less about unhandled exception filters, which are interesting routines that allow you to gain control right before that Application Error dialog box that drives your users crazy pops up. Whereas exception handlers are C++ specific, unhandled exception filters work for both C and C++ code.

In this chapter, I'll present code that you can drop into your applications to get crash information such as registers and call stacks. In addition, the code will hide much of the dirty work of gathering this information for you so that you can concentrate on reporting the information that is unique to your application and on presenting a better face to the user. As part of this information gathering, I'll also cover how to get the most out of the excellent MiniDumpWriteDump API function so that you can get minidumps any time you need them. Before I can jump into the code, however, I need to spend some time describing the various types of exception handling in Microsoft Win32 systems.




Debugging Applications for Microsoft. NET and Microsoft Windows
Debugging Applications for MicrosoftВ® .NET and Microsoft WindowsВ® (Pro-Developer)
ISBN: 0735615365
EAN: 2147483647
Year: 2003
Pages: 177
Authors: John Robbins

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net