Mark said:
I have worked out the code in a sample application for recording to the
event log in windows. What are your suggestions for communicating
errors among different parts of my application. If one function didn't
do what was expected I return FALSE and set a variable LAST_ERROR to an
error code so the calling function can do what ever is needed to handle
the error. Sometimes the error isn't severe so nothing needs to be
done, I just want a record of it.
When you have an error that requires an interruption to the normal order
of your program, you can "throw an exception" up the call stack, and
"catch" it at whatever level seems appropriate. The stack is unwound
for you automatically. This is sort of like C's setjmp/longjmp
facility, but the stack is unwound correctly, so destructors are called
and resources can be released. Also, because exceptions give you an
alternative to the normal way of unwinding the stack, you don't have to
check for errors after each function call. If an error occurs, the code
you provide for handling it will be invoked automatically.
Like pretty much everything else in C++, exceptions are based on the
language's types. Instead of specifying different a different block of
code to execute for each error number (as with a switch(errno)
statement), you specify a different block for each type of exception.
Thanks to multiple inheritance, a given exception can be caught by any
of several different handlers, each of which catches a reference to a
different base class of the exception.
If you have a good book on C++ (like _The C++ Programming Language_
Special Edition, by Stroustrup), look up exceptions, and particularly
the throw and catch keywords.
Good luck,
Jeff