tag:blogger.com,1999:blog-1625401331703494000.post2427780408926406334..comments2023-07-01T06:18:43.993-07:00Comments on Darren's Developer Diary: Windows SEH in C++Anonymoushttp://www.blogger.com/profile/03151050273122725547noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-1625401331703494000.post-14804560649414045352011-12-10T17:13:56.364-08:002011-12-10T17:13:56.364-08:00Thanks Anon, well-spotted. I dragged More Effectiv...Thanks Anon, well-spotted. I dragged More Effective C++ off the shelf, and read items 12 and 13, and I think you may be right. In fact catching by reference is correct, <i>throwing by pointer</i> is what is dubious. So I think my SEH handler should have been written like this (i.e. without the <b>new</b>):<br /><br />void win32_exception_handler(unsigned int code, EXCEPTION_POINTERS *ep){<br />throw win32_exception(code,ep);<br />}Anonymoushttps://www.blogger.com/profile/03151050273122725547noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-38428624977407237442011-12-09T15:54:35.972-08:002011-12-09T15:54:35.972-08:00My guess : you mispelled the exception type . Shou...My guess : you mispelled the exception type . Should have writen :<br /><br />catch(win32_exception *e){<br />ErrorLog()<<"Caught win32_exception thrown by main_loop:"<what()<<" (will treat as fatal)\n";<br />return -9;<br />}Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-62640063537884143432009-09-10T06:28:34.597-07:002009-09-10T06:28:34.597-07:00SysInternals web site and forum may be useful reso...SysInternals <a href="http://207.46.16.252/en-us/sysinternals/bb842062.aspx" rel="nofollow">web site</a> and <a href="http://forum.sysinternals.com/" rel="nofollow">forum</a> may be useful resources.Keithhttps://www.blogger.com/profile/02766086688180574504noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-18138888598013135222009-09-07T16:24:45.761-07:002009-09-07T16:24:45.761-07:00A curious breakthrough: my win32_exception_handler...A curious breakthrough: my win32_exception_handler() *is* being called, and I can log it from there. But when I throw a win32_exception it doesn't get caught as that, but in the "..." block instead.<br /><br />My wild guess is that my win32_exception_handler applies to the whole application, but the error comes out of some deep DLL which isn't able to throw a C++ exception properly.<br /><br />Anyway, if you're having a similar problem, and not planning to recover, try logging from win32_exception_handler() instead of, or as well as, throwing a C++ exception.<br /><br />P.S. The problem code is 3221225477, which is C0000005 in hex, which is EXCEPTION_ACCESS_VIOLATION.Anonymoushttps://www.blogger.com/profile/03151050273122725547noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-7741324792805536972009-09-06T21:23:46.784-07:002009-09-06T21:23:46.784-07:00My 4th edn. Windows Internals book has about seven...My 4th edn. Windows Internals book has about seven pages on Exception dispatching; it also says that SEH is explained in Windows API Ref. Docs. of the Platform SDK or in a book by Richter (who has a much later book Windows via C/C++ ISBN: 0735624240 which seems to cover the same stuff). You have probably already looked at <a href="http://msdn.microsoft.com/en-us/library/ms679327(VS.85).aspx" rel="nofollow">MSDN</a>Keithhttps://www.blogger.com/profile/02766086688180574504noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-10387325428943136772009-09-06T15:54:43.248-07:002009-09-06T15:54:43.248-07:00So far the best lead I've found is that if a D...So far the best lead I've found is that if a DLL was not compiled with /EHa then my application using that DLL may have trouble catching it.<br />And, separately, I found a reference saying unhandled SEHs can get caught by a catch(...) block.<br /><br />So, my plan is now to surround smaller blocks of code with try/catch blocks to try and narrow down where the SEH is arising.Anonymoushttps://www.blogger.com/profile/03151050273122725547noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-27662709381699419012009-09-06T15:48:30.678-07:002009-09-06T15:48:30.678-07:00Hi Keith,
If I can manage to catch the exception i...Hi Keith,<br />If I can manage to catch the exception it will tell me useful things like EXCEPTION_ACCESS_VIOLATION, EXCEPTION_FLT_DIVIDE_BY_ZERO, EXCEPTION_STACK_OVERFLOW.<br /><br />I.e. I'm trying to find out what the problem; then I'll start looking into fixes (which may involve telling someone else their code has a problem ;-).Anonymoushttps://www.blogger.com/profile/03151050273122725547noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-52650439964986079772009-09-04T19:09:09.017-07:002009-09-04T19:09:09.017-07:00ISBN 0735625301 and 0735626618.ISBN 0735625301 and 0735626618.Keithhttps://www.blogger.com/profile/02766086688180574504noreply@blogger.comtag:blogger.com,1999:blog-1625401331703494000.post-19937589210619788912009-09-04T16:22:34.615-07:002009-09-04T16:22:34.615-07:00I'm not a Windows developer, so I don't kn...I'm not a Windows developer, so I don't know *if the following ideas are off track, *whether you're aware of the following resources, and whether they will be of help. Maybe you are presuming that the program died because it detected a fatal internal error in the program, but it could have died because Windows killed it for some reason. <a href="http://blogs.technet.com/Sysinternals/" rel="nofollow">SysInternals</a> and <a href="http://en.wikipedia.org/wiki/Winternals" rel="nofollow">Windows Internals</a> may be useful resources (there are books by those names on Amazon, I think).Keithhttps://www.blogger.com/profile/02766086688180574504noreply@blogger.com