Click here to Skip to main content
Licence 
First Posted 27 May 2000
Views 66,672
Bookmarked 47 times

Handle Application Crashes Better

By | 2 Jun 2000 | Article
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

    About the Author

    Shane Hyde

    Web Developer

    Australia Australia

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    Generalcan't use with Thread??? [modified] PinmemberMotorcure4:32 11 Aug '08  
    Generaldon't work with VS 2005 and SP 1 PinmemberFrameFever5:57 15 Jun '07  
    GeneralRe: PinmemberNonamedAuthor21:18 29 Aug '05  
    QuestionHow to get debug info from DLL we have loaded Pinsusscoolvcguy2:20 19 Dec '02  
    GeneralGood, but.. PinsussMark Ivison23:45 24 Jul '00  
    QuestionHow to interpret the stack dump PinsussMichael Walz23:41 4 Jun '00  
    AnswerRe: How to interpret the stack dump PinsussShane Hyde4:31 5 Jun '00  
    GeneralRe: How to interpret the stack dump PinmemberAnonymous14:51 29 Jun '01  
    GeneralSmall bug PinsussShane Hyde5:00 31 May '00  
    GeneralRe: Small bug PinmemberMatt J. Lee23:19 12 Jul '01  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.5.120517.1 | Last Updated 3 Jun 2000
    Article Copyright 2000 by Shane Hyde
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid