Question on Exception handling.

Using Visual C6.
What I would like to do is build a general purpose Exception handling class.
What I need to do is this, on ANY error within a TRY block I want the catch statement to take the windows error number and pass it to the class as a pointer so I can retrieve the windows error number and the error description along with some other useful information and be able to save it to the users hard drive. What I’m not sure about is how to go about catching the number, do I use GetLastError or GetErrorInfo or what?

I don’t know about you but I got tired of users telling me that they had gotten an error and when you ask them what the error said, their reply is “ oh I forgot to write it down” or when asked what they were doing “I don’t remember exactly what I was doing when it happened”. So I created a function in Visual Basic that I could pass the windows error number, the block of code that was running at the time of the error and approximately where in the block (about every tenth line or so) the program caused the error. This along with some information about the users machine I write to a text file on the users machine, this way I can have them email me the file.

Comments

  • : Using Visual C6.
    : What I would like to do is build a general purpose Exception handling class.
    : What I need to do is this, on ANY error within a TRY block I want the catch statement to take the windows error number and pass it to the class as a pointer so I can retrieve the windows error number and the error description along with some other useful information and be able to save it to the users hard drive. What I’m not sure about is how to go about catching the number, do I use GetLastError or GetErrorInfo or what?
    :
    : I don’t know about you but I got tired of users telling me that they had gotten an error and when you ask them what the error said, their reply is “ oh I forgot to write it down” or when asked what they were doing “I don’t remember exactly what I was doing when it happened”. So I created a function in Visual Basic that I could pass the windows error number, the block of code that was running at the time of the error and approximately where in the block (about every tenth line or so) the program caused the error. This along with some information about the users machine I write to a text file on the users machine, this way I can have them email me the file.
    :
    :

    Use GetLastError() to retrieve the last system error number after any falure. Or, if you want the system error description, use FormatMessage() to get it.
    [CODE]
    void CYourAppDlg::HandleSystemError()
    {
    LPVOID lpMsgBuf;
    FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER |
    FORMAT_MESSAGE_FROM_SYSTEM |
    FORMAT_MESSAGE_IGNORE_INSERTS,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    (LPTSTR) &lpMsgBuf,
    0,
    NULL
    );

    // log it, display it, or whatever...
    AfxMessageBox((LPCTSTR)lpMsgBuf);
    LocalFree( lpMsgBuf );
    }[/CODE]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories