MFC support for thrown exceptions.
Paul Martinsen -- pmartinsen@hort.cri.nz Thursday, November 28, 1996 Environment: Windows 95, MSVC 4.0 Hello, I have been wondering if the MFC libraries provide any default support for handling exception that have been thrown. For example the following code will throw a resource exception if the display context can't be created: void CMyView::DrawSomeStuff() { CClientDC dcMyView(this); dcMyView.MoveTo(0,0); dcMyView.DrawTo(100,100); : : } What will happen when the exception occurs. My guess is that the debug code will ASSERT, but will a release version crash? Should it have been coded: void CMyView::DrawSomeStuff() { try { CClientDC dcMyView; dcMyView.MoveTo(0,0); dcMyView.DrawTo(100,100); : : } catch (...) { // Couldn't do drawing. User won't see anything, // but better than program crashing. } } Is there any way of testing these sort of things (system runs out of resources/ disk space/ memory) without buying more expensive software? Thanks, Paul Martinsen.
Mike Blaszczak -- mikeblas@nwlink.com Saturday, November 30, 1996 At 13:11 11/28/96 +1200, Paul Martinsen wrote: >Environment: Windows 95, MSVC 4.0 >I have been wondering if the MFC libraries provide any default >support for handling exception that have been thrown. Any message that MFC ends up disptaching is done in the context of a backstop exception handler. You can see the code for it in the AfxCallWndProc() function in WINCORE.CPP. There are some special case handlers (for exceptions thrown during the creation of a window, for example). There are also some functions which are expected to throw an exception, like DoDataExchange(), where MFC has other special purpose exception handlers. >Should it have been coded: Yes. As a rule, when writing software, you should anticipate error conditions that can crop up and do something graceful about them. MFC's default handler will try to show a reasonable error for the exception that was encountered. If you don't like what MFC does, you can override ProcessWndProcException() in your CWinApp-derived class. >Is there any way of testing these sort of things (system runs out of >resources/ disk space/ memory) without buying more expensive >software? I'm not at liberty to check at the moment, but I think the Win32 SDK has a tool in it called STRESS. It allows you to force certain low-resource conditions in a controlled way. .B ekiM http://www.nwlink.com/~mikeblas/ I'm afraid I've become some sort of speed freak. These words are my own. I do not speak on behalf of Microsoft.
| Вернуться в корень Архива |