
Exceptions : Combining C++ and Structured Exception Handling ?
Hi All,
To my knowledge :
Structured Exception Handling (SEH) provides a means to deal with
problems such as memory access violations, divide by zero and
so forth.
The C++ CException and derived classes provide a means to
handle memory allocation errors and the like - but not the more
low level errors captured by the SEH system.
My problem !
Microsoft say that in MFC applications you are best to use the
C++ methods (ie. try, throw, catch). The old macro method is
to be avoided at all costs. In discussing the SEH system they
(the documentation) says it is robust but as it is not C++ specific
the c++ method (try, etc) is preferred.
Now I have an application, in which I would like to trap low level
errors, such as divide by zero, memory access and would also
like to trap my own exceptions, which will be derived from CException.
(This is form of handling is needed because I am writing container
code which is intended to test other code - the other code may
not be well written and the container code needs to be capable
of trapping errors and continuing).
I have not been able to handle memory access violations through the
c++ exception system, the only way I have found to handle these
is to use the SEH system of __try and __except.
I have also found that the compiler will not let you use the two forms
of exception handling (SEH and c++) in the same function.
The question !
What is the preferred way (or how do I) handle exceptions generated
from my own throws and also those generated through SEH (ie. Memory
access violations).
Thanks for your time,
Gareth
My attempts at using c++ exceptions to catch a memory access violation
- just so we're talking about the same thing
try {
int *p = 0;
*p = 13;
}
catch (exception except) {
TRACE0("woah\n");
}
catch (CException except) {
TRACE0("Error\n");
}
catch (unsigned int except) {
TRACE0("Hello\n");
}