Byron Cook: Inside Terminator

Glad you enjoyed this! You can expect to see some more very interesting videos from Microsoft's C++ World...
C
Yes the EH state is stored as 32 bits on Win32. You need a new state for each new C++ object, and for each new try block you enter. If you overflowed that state, things would go very wrong.
However, there are many other limits you would hit before hitting this one. The compiler has limits on how big a function can be, how many objects it can have, how many curlies can be opened, etc.
Even if you could compile your program, you would run out of stack space to store all these objects, and your program wouldn't fit in memory (a state update is more then a byte).
-- Louis Lafreniere
We do have plans for a Channel 9 video on the upcoming MFC extensions – all going well look for these towards the end of this year.
FYI: for a sneak preview I should mention that Ale is presenting at TechEd Europe: Developer in Barcelona on the MFC extensions in November - information below.
Thanks
Damien Watkins
Visual C++
--
Title/Code: TLA404 MFC Updates for Visual Studio 2008 and Beyond
Presenter: Ale Contenti
Abstract: This session will demonstrate the new features added to MFC in Visual Studio 2008, including support for Vista Common Dialogs, Vista Common Controls, the Microsoft Office 2007 Look and Feel (including support for an Office Ribbon style interface), Office and Visual Studio style Docking Toolbars and Tabbed Documents. We will also talk about our plans to evolve the MFC library for Visual C++ 10 and beyond. This is an in-depth session designed for experienced C++/MFC programmers. (C)
Hello
The preference for this general functionality to be “in the box” is a customer comment we have heard loud and clear. There will always be room for third parties to add great value in areas we cannot cover but to be truthful we should have done more over recent years and I hope you are delighted with the upcoming extensions.
Thanks
Damien
I'll try to answer your questions as best as I can:
Is some big buffer allocated into which they are placed, on a per-stack basis (in which case, who allocates it?
When an object is thrown by value, the compiler emits a copy constructor to copy it to the argument stack of throw(). If the catch catches by value, the object argument of the throw will then be copy constructed by the CRT to the argument stack of the
catch.
What if I stupidly use CreateThread instead of _beginthreadex)?
Ale could probably better answer this one, but in general you should always use _beginthread or _beginthreadex when using the CRT to make sure the CRT internal data structures are properly initialized. I don't recall that EH uses any global data structure,
but I could certainly be wrong here.
Is the exception constructed first and copied there (or else what happens when an exception is thrown during exception object construction - when is the exception considered thrown)?
I think I've answered the first part of your question. For the second part, the exception is considered "thrown" once the throw() has called RtlRaiseException(). So in the scenario above, if the first copy-ctor throws, the first exception had not been
officially thrown yet, so the new exception takes over. If the second copy-ctor throws (copying to the catch), the CRT will catch the exception and call terminate().
How big can an exception object be?
As long as it can fit on the stack I believe! That's if you throw and/or catch by value of course.
If I do something silly to increase the alignment of a class, is that handled?
Since we don't support __declspec(align) on parameters, the answer is no.
How do exception frames work within exception handlers? So on.
Are you asking about how we handle the case where there is a try/catch inside a catch block? The catch handler actually shares the same EH frame/tables as the parent function. On Win64, the handler of course have separate unwind entries, but do share the
IP (instruction pointer that is ) to EH state table.
I hope this helps!
EH is a very broad subject and there are many facets to it which could each be a talk on its own: perf, usability and best practices, security, under the hood implementation, etc. I think we tried to cover the most important part of each of these (it's true
that we didn't touch security though), but we do need to keep these videos down to a reasonable lenght.
-- Louis Lafreniere
about the last question on CreateThread vs. _beginthread, the C++ runtime DLL will take care of creating the PTD (per-thread-data) slot and associating it with the thread. Check the code in DLL_THREAD_ATTACH in the CRT DllMain.
Like Louis says, it is better to use _beginthread, but CreateThread will work anyway.
Also, during the video I mentioned Herb's book "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices" (link here
And how do you get your Watson dumps? It's pretty easy (special thx to Jason Hardester for the info):
Go to https://winqual.microsoft.com and:
1. Establish a company account on Winqual
2. Sign (online click through) the WER TOU agreement
3. Map your files using APPMAP.exe
Ale (see you in Barcelona )