Re: Exception Handling
"Ben Menashe" <BenMenashe@discussions.microsoft.com> wrote in message
news:B60387EF-BE7C-4E70-BED9-7EA4D21068EC@microsoft.com...
I'm trying to test a concept of global TRY CATCH in my service...
basically
as it starts I create one object and call a function to handle the
functionality of the service. Sometimes there are crashes and not exactly
sure where they come from... of course the source of the problem should be
fixed... but we must avoid ugly GPFs to the users. So that's why thinking
of
a global TRY/CATCH...Is this a valid approach ?
I was doing some experiment, but I can't even get a simple exception to
catch... any ideas ? here's the simple test code below... and in the
project
settings I do have exception handling enabled. THANKS !!
//cause test crash
try
{
char *p = 0;
cout << strlen(p) << '\n'; //this will cause GPF
}
catch(...)
{
//does not get here for some reason...
}
There is an awful lot to say on this topic. See my friend Doug's essay here:
http://members.cox.net/doug_web/eh.htm
Realize basically that you are conflating two concepts: structured
(platform) exceptions that are indicative of serious programming errors and
C++ (typed) exceptions which report on far more benign conditions.
There is a school of thought that says you should just crash an application
on encountering a wild pointer error like the one you are trying to simulate
above. The idea is that that is evidence of a serious programming error and
by the time the error is raised your application may be trashed to the
extent that continuing risks further damage.
Still, in development it's nice to know what causes an exception. To that
end. I have a structured exception class and a VS.Net project that
demonstrates how to use it here:
http://www.ivrforbeginners.com/downloads/downloads.htm
If you do that, the structured exception will get translated to a typed
exception which the "catch-all" catch clause will catch.
It may be just my bias, but I don't like the looks of catch-all clauses. I'd
much prefer to tell the compiler what I want to catch and how to handle it.
YMMV.
Regards,
Will