Newsgroups: comp.windows.ms.programmer Path: utzoo!utgpu!watserv1!watmath!hyper.hyper.com!bonneau From: bonneau@hyper.hyper.com (Paul Bonneau) Subject: Re: question regarding catch/throw Message-ID: <1991Mar28.191907.21710@hyper.hyper.com> Keywords: catch throw setjump longjump Reply-To: bonneau@hyper.UUCP (Paul Bonneau,,) Organization: HyperCube Inc. References: <1991Mar27.182820.17579@cuff.uucp> Date: Thu, 28 Mar 1991 19:19:07 GMT In article <1991Mar27.182820.17579@cuff.uucp> boag@cuff.uucp (Scott Boag) writes: >We are about to implement a generalized error handling scheme that uses >catch/throw (i.e. setjump/longjump). I am a bit worried about the >behavior of these functions in the MS Windows environment. Has anyone >had prior experience with using these? Thanks in advance. > There are some gotchas to look out for. The major problem is that Windows does not set any Catch()points itself, and as a result its internal state gets screwed up. For example, if you restrict the mouse with ClipCursor() and bag out, the cursor will still be restricted to the rectangle you set. We use Catch() and Throw() in our code, but it only works acceptably if you are careful to set a Catch()point in each routine on the stack that needs to clean up. Even so, I am still have the uneasy feeling it is possible to leave Windows in a weird state, regardless of how careful you are. For example, suppose you run out of memory in response to a WM_KILLFOCUS message, while the focus is being moved to another one of your app's windows. You Throw() up to the main loop and exit the program. The window to receive the focus never got it, since it was destroyed first. But the internal focus variable in User still references the now defunct window. There is no way to handle a situation like this in the app, other than allowing the WM_SETFOCUS message to be received before exiting, which may nto be easy to do. You cannot simply call SetFocus() to another app's window in response to the WM_KILLFOCUS, since SetFocus() is not re-entrant. Hope this helps, cheers - Paul Bonneau.