Posted By: Charles | Sep 20th, 2007 @ 5:47 PM | 25,714 Views | 19 Comments
Sometimes, things go wrong when code executes. You can't predict when this will happen or even why, but you can write code to handle exceptional problems. If you're lucky, the problem will carry with it a bunch of useful information that you can use, at runtime, to handle the specific error. These exceptional information structures are called structured exceptions; blobs of bad news carrying useful and specific information that you can use to find your way out of the exceptional rabbit hole. Of course, with useful data packaged up in an exception you can more easily debug to find root causes, which is much harder to do with, say, error codes...

What is a structured exception, exactly? How should you handle exceptions that you don't assume will arise during the execution of your code? What are the correct patterns of exception handling that you can safely rely on? What does the C++ compiler have to do with exception code patterns?

Come along for ride into the deep and murky world of exceptions with some folks that truly understand them at the most fundamental levels.

Ale Contenti is a senior development lead in the C++ base class libraries team. Louis Lafreniere is a principal software developer in the C++ compiler group. Here, Ale and Louis teach us about exceptions and handling them (and when not to handle them). I love talking to the VC++ People. They live on the metal and really understand the fascinating intracacies of our platform.

Enjoy this latest Going Deep episode.
Media Downloads:
Rating:
1
0
yes, yes! another interview with the vc++ team! i just can't wait to see the thing i've read on herb sutter's blog recently: "The thing we can't talk about but that has something to do with MFC". I suppose it's more than MFC 9.. i hope..
anyway, thanks a lot, Charles, for these going deep videos - especially the ones from c++ land.
i really liked the comparison between throw and beep Smiley and unmanaged and managed world

very nice interview, thanks Charles!
Ok, I had to stop the video just now (roughly the 30 minute mark) where you are discussing the states in a function and how you keep track of the state. (i.e. -1, 0, 1, 2, 1, 0, -1).

One question, if some nut wrote a function with more states than your long integer (assuming you are using a long int) can handle, would it crash ? and if so how bad.

Very kewl and Charles can we get more videos to discuss low level topics such as this.

back to the video I go  !  Good work guys...


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). Smiley

-- Louis Lafreniere

Hello

Re: the comment from mwirth

> "The thing we can't talk about but that has something to do with MFC". I suppose it's more than MFC 9.. i hope.. 

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)   

Thanks for your reply, damien! Just reading the abstract for this talk you mentioned assures me that it's ok for me to stay with native c++ for quite a while Smiley its so great that we might be getting a usable and current framework for windows development from microsoft again. i don't really enjoy using third party UI frameworks...

Cheers!
Martin

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 was hoping to hear more about where the exception objects 'live' until they're caught:
  • Is some big buffer allocated into which they are placed, on a per-stack basis (in which case, who allocates it? What if I stupidly use CreateThread instead of _beginthreadex)?
  • 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)?
  • How big can an exception object be?
  • If I do something silly to increase the alignment of a class, is that handled?
  • How do exception frames work within exception handlers? So on.
Great video otherwise, but it would have been nice to get further into the implementation details beyond "We have a linked list of frames at FS:0 on x86 and a table of handlers based on instruction addresses for x64". For example, a while ago I saw Brandon Bray give a great presentation on SafeSEH, which wasn't even mentioned here.

Regards,
James.

Microsoft Communities