Click here to Skip to main content
16,018,904 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VLC player Pin
gmallax8-Mar-10 18:24
gmallax8-Mar-10 18:24 
GeneralRe: VLC player Pin
gmallax9-Mar-10 22:45
gmallax9-Mar-10 22:45 
Questionhow to use CHtmlEditView in vc 6.0 Pin
sunnyram7-Mar-10 22:49
sunnyram7-Mar-10 22:49 
GeneralRe: how to use CHtmlEditView in vc 6.0 Pin
Rage8-Mar-10 4:15
professionalRage8-Mar-10 4:15 
GeneralRe: how to use CHtmlEditView in vc 6.0 Pin
sunnyram15-Mar-10 3:06
sunnyram15-Mar-10 3:06 
Questionerror scenerio handling Pin
hrishi3217-Mar-10 22:46
hrishi3217-Mar-10 22:46 
AnswerRe: error scenerio handling Pin
Richard MacCutchan8-Mar-10 1:09
mveRichard MacCutchan8-Mar-10 1:09 
AnswerRe: error scenerio handling Pin
Jonathan Davies8-Mar-10 3:28
Jonathan Davies8-Mar-10 3:28 
From experience I've settled on three classes:

1.CMessage: containing the description of an error, though a message doesn't have to describe just an error - "Application started" and "Application stopped", for example, can be included alongside "Widgit X fell over". Initially I used a .h file for this but migrated to using a .mc file as well, the .mc being compiled to produce a .rc resource file.

2.CEventLog: containing some means of logging a message. I started logging to a .txt file, moved to .html and now log to the Windows Event Log via the ReportEvent [^] function.

3.CExError which can be thrown and has a constructor which takes the error information and logs it.

The most productive tactic by far I found was to ensure the file and line numbers where the error occurred were included in the message by using macros such as:

#define AT __FILE__ ":" TOSTRING(__LINE__)


Importantly I found this was a maintainable and expandable (relatively easy to add or edit messages) strategy which:

1. Didn't obscure the actual point of the code (too much) with line after line of error handling.
2. Completely hid away logging of errors in the CExError constructor,
3. Moved away (to the catch block) the point at which any code written to recover needed to go.

So the actual code ended looking something like:

...
void someclass::somefunction(...)
{
    try 
    {
    
        if(!AttemptSomething(param1, param2)
        {
            throw CExError(MESSAGE_ID_1, "Context info", AT);
        }

        if(!AttemptSomethingelse(param1, param2)
        {
            throw CExError(MESSAGE_ID_2, "Context info", AT);
        }
    }
    catch(CExError& err)
    {
        //Decide what to do about any error here, such as:
        if(MESSAGE_ID_2 == err.MessageID)
        {
            MessageBox(err.Message);
        }
    }
    return;
}

...

QuestionProblem with DLL running in parallel Pin
Llasus7-Mar-10 22:43
Llasus7-Mar-10 22:43 
AnswerRe: Problem with DLL running in parallel Pin
Graham Breach7-Mar-10 23:21
Graham Breach7-Mar-10 23:21 
GeneralRe: Problem with DLL running in parallel Pin
Llasus8-Mar-10 1:50
Llasus8-Mar-10 1:50 
QuestionHow could I monitor the network adapter status ? Pin
EverettJF7-Mar-10 22:10
EverettJF7-Mar-10 22:10 
QuestionRe: How could I monitor the network adapter status ? Pin
Adam Roderick J7-Mar-10 22:39
Adam Roderick J7-Mar-10 22:39 
AnswerRe: How could I monitor the network adapter status ? Pin
EverettJF8-Mar-10 14:12
EverettJF8-Mar-10 14:12 
AnswerRe: How could I monitor the network adapter status ? Pin
Cool_Dev7-Mar-10 22:45
Cool_Dev7-Mar-10 22:45 
QuestionRe: How could I monitor the network adapter status ? Pin
David Crow8-Mar-10 5:52
David Crow8-Mar-10 5:52 
AnswerRe: How could I monitor the network adapter status ? Pin
EverettJF8-Mar-10 19:34
EverettJF8-Mar-10 19:34 
QuestionA problem of using CScrollView [modified] Pin
whiteclouds7-Mar-10 21:57
whiteclouds7-Mar-10 21:57 
GeneralRe: A problem of using CScrollView Pin
Rage8-Mar-10 4:19
professionalRage8-Mar-10 4:19 
GeneralRe: A problem of using CScrollView Pin
whiteclouds8-Mar-10 14:13
whiteclouds8-Mar-10 14:13 
GeneralRe: A problem of using CScrollView Pin
Rage8-Mar-10 4:24
professionalRage8-Mar-10 4:24 
QuestionLinker error - MFC DLL - missing constructor??? Pin
Vaclav_7-Mar-10 19:52
Vaclav_7-Mar-10 19:52 
AnswerRe: Linker error - MFC DLL - missing constructor??? Pin
Eugen Podsypalnikov7-Mar-10 20:29
Eugen Podsypalnikov7-Mar-10 20:29 
GeneralRe: Linker error - MFC DLL - missing constructor??? Pin
Vaclav_8-Mar-10 5:31
Vaclav_8-Mar-10 5:31 
GeneralRe: Linker error - MFC DLL - missing constructor??? Pin
Eugen Podsypalnikov8-Mar-10 19:47
Eugen Podsypalnikov8-Mar-10 19:47 

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.