Click here to Skip to main content
Click here to Skip to main content

Handle Application Crashes Better

, 2 Jun 2000
Rate this:
Please Sign up or sign in to vote.
A method of getting more details about application crashes.
<!-- Link to demo file download -->
  • Download demo project - 24 Kb
  • <!-- Article image -->

    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

    About the Author

    Shane Hyde
    Web Developer
    Australia Australia
    No Biography provided

    Comments and Discussions

     
    Generaldon't work with VS 2005 and SP 1 PinmemberFrameFever15-Jun-07 5:57 
    GeneralRe: PinmemberNonamedAuthor29-Aug-05 21:18 
    QuestionHow to get debug info from DLL we have loaded Pinsusscoolvcguy19-Dec-02 2:20 
    GeneralGood, but.. PinsussMark Ivison24-Jul-00 23:45 
    QuestionHow to interpret the stack dump PinsussMichael Walz4-Jun-00 23:41 
    AnswerRe: How to interpret the stack dump PinsussShane Hyde5-Jun-00 4:31 
    GeneralRe: How to interpret the stack dump PinmemberAnonymous29-Jun-01 14:51 
    GeneralSmall bug PinsussShane Hyde31-May-00 5:00 
    GeneralRe: Small bug PinmemberMatt J. Lee12-Jul-01 23:19 

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

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

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140721.1 | Last Updated 3 Jun 2000
    Article Copyright 2000 by Shane Hyde
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid