Re: Timerproc exception
On Fri, 5 Oct 2007 03:43:03 -0700, Geoff Cohen
<GeoffCohen@discussions.microsoft.com> wrote:
I have a UI thread whose only function is to start a timer which uses a
timerproc callback
void CALLBACK timerproc (HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
Trying to trace a random deadlock bug I found that on occasion the callback
would cause an exception in the C library function fgets (called with a NULL
file pointer). What surprised me is that the exception (which neither
CException nor std::exception seems to catch) just has the effect of silently
exiting from the timerproc. The timer fires again and the application
continues. Is this behaviour normal? I would have expected the application to
crash.
The timerproc exit doesn't appear to unwind the stack and so left critical
sections locked (although wrapped in CSingleLock-type variables on the stack).
Any comments would be appreciated.
Thanks
You haven't indicated how you determined it was an "exception", so I'll
guess it was an access violation, which is a Windows structured exception,
not a C++ exception. If you are using catch(...) and compiling with /EHa,
you will catch SEs in catch(...), which is really unfortunate as I explain
here:
http://members.cox.net/doug_web/eh.htm
Even if you are compiling with /EHs, VC 2003 and earlier will catch SEs in
catch(...) in many cases. If you are using catch(...) and catching an
access violation there, well, you've experienced the "hinders debugging"
reason why this is such a bad idea. Of course, it's also possible to
swallow SEs with __try/__except, and without knowing more about your code,
it's impossible to say with certainty what's happening.
--
Doug Harrison
Visual C++ MVP