Click here to Skip to main content
15,881,092 members
Articles / Desktop Programming / MFC
Article

Handle Application Crashes Better

Rate me:
Please Sign up or sign in to vote.
3.73/5 (5 votes)
2 Jun 2000 81.9K   863   47   10
A method of getting more details about application crashes.
  • Download demo project - 24 Kb
  • Sample Image - DumpHandle.gif

    Motivation

    When dealing with application crashes, customers don't always send details of the crash when they report problems. They often don't realise they have to press the Details button, they dont tell you which version it is, or they might get Dr Watson dumps. Either way, you get either too much information, or not enough.

    Having seen Martin Ziacek's article "SEH and C++ Exceptions - catch all in one" article, this provided me with a method to get better application crash handling.


    Implementaion

    Martin's article shows how to gain control after an Exception, what was needed was to present the information to the user. Firstly I added some code to traverse the stack in a backwards fashion, and collect all the adresses of all the calls.

    void SeTranslator(UINT nSeCode, _EXCEPTION_POINTERS* pExcPointers)
    {
    	CSeException *se = new CSeException(nSeCode, pExcPointers);
    
    	/*
    	**  Save the last 32 functions called
    	*/
    	DWORD * sp = (DWORD *)(pExcPointers->ContextRecord->Ebp);
    	for(int i=0;i<32;i++)
    	{
    		if(!IsBadReadPtr(sp,sizeof(DWORD)) && *sp)
    		{
    			DWORD *np = (DWORD *)*sp;
    			se->m_StackTrace[i] = *(sp+1);
    
    			sp = np;
    		}
    		else
    			se->m_StackTrace[i] = 0;
    	}
    	throw se;
    }

    This way, when the application regains control after the throw, the stack at the time of the crash is known.


    Implementation

    All that is needed now is to present the crash details to the user. This is done by deriving your application object from CDumpHandleApp instead of CWinApp. CDumpHandleApp does the rest. In the InitInstance you need to add a call to the base class CDumpHandleApp::InitInstance and to set the support email address.

    BOOL CDumpHandleDemoApp::InitInstance()
    {
    	/*
    	**  Initialize the dumper code
    	*/
    	if(!CDumpHandleApp::InitInstance())
    		return FALSE;
    
    	m_strSupportEmail = "shyde@trontech.net";

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Web Developer
    Australia Australia
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    Generalcan't use with Thread??? [modified] Pin
    Motorcure11-Aug-08 4:32
    Motorcure11-Aug-08 4:32 
    Generaldon't work with VS 2005 and SP 1 Pin
    FrameFever15-Jun-07 5:57
    FrameFever15-Jun-07 5:57 
    GeneralRe: Pin
    Member 183035229-Aug-05 21:18
    Member 183035229-Aug-05 21:18 
    QuestionHow to get debug info from DLL we have loaded Pin
    coolvcguy19-Dec-02 2:20
    coolvcguy19-Dec-02 2:20 
    GeneralGood, but.. Pin
    Member 6855624-Jul-00 23:45
    Member 6855624-Jul-00 23:45 
    QuestionHow to interpret the stack dump Pin
    Michael Walz4-Jun-00 23:41
    Michael Walz4-Jun-00 23:41 
    AnswerRe: How to interpret the stack dump Pin
    Shane Hyde5-Jun-00 4:31
    Shane Hyde5-Jun-00 4:31 
    GeneralRe: How to interpret the stack dump Pin
    29-Jun-01 14:51
    suss29-Jun-01 14:51 
    GeneralSmall bug Pin
    Shane Hyde31-May-00 5:00
    Shane Hyde31-May-00 5:00 
    GeneralRe: Small bug Pin
    12-Jul-01 23:19
    suss12-Jul-01 23:19 
    Err..
    void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);

    not __stdcall but __cdecl

    Am I wrong?

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.