During Ale Contenti's first Channel 9 video (VC++ Safe Libraries and More) he was asked how the Safe CRT worked with exceptions. This was a great question, but too much to handle at the time. Ale suggested the topic was worth a whole other video...and so here it is! Ale is joined in this video by Louis Lafreniere (developer on the backend) to give you the whole picture - including how exception handling is implemented (even describing the variations caused by different hardware) and optimized. You can find the new video here.
This video is deep, and at 55 minutes fairly long, so get a fresh coffee, allocate some time and sit down to enjoy this one.
PingBack from http://msdnrss.thecoderblogs.com/2007/09/21/channel-9-ale-contenti-and-louis-lafreniere-understanding-exceptions-and-whenhow-to-handle-them/
Is there any way to catch the win32 exception generated when accessing an out-of-bound element in a std::vector using operator? If there is, how?
That is called Structured Exception Handling (SEH), which is completely different from C++ exception handling.
Most applications should never attempt to intercept SEH.
What are you really trying to do? You shouldn't be generating out-of-bounds accesses with op in the first place.
Stephan T. Lavavej, Visual C++ Libraries Developer
Thanks for your reply, Stephan. I understand we should check bounds with op in the first place. But in reality, things like this do happen. What I am trying to do is to catch SEH exceptions like this (or division by zero etc.), save the critical data and exit the application.
The trouble I have is the /EHa compiler option would not work for me. I can catch division by zero SEH exception only with optimization turned off. I can not catch out-of-bound SEH exception in std::vector op at all. Any suggestions?
I am using Visual C++ 2005.
My doubt for exceptions is the following.
Suppose that I want to use STL inside a COM server that I develop using ATL.
While it is possible to use C++ exceptions (e.g. the std::exception and derived classes) *inside* the COM server, my understanding is that it is not allowed to throw exceptions out of COM method boundaries. In fact, the HRESULTs should be the only option to signal errors outside COM methods boundaries.
So, to build quality code, do you suggest us to put try/catch( std::exception & ) blocks inside each COM object method implementation, to prevent C++ exceptions to escape COM object methods boundaries?
Thanks in advance, and congrats for the Channel 9 video.
Yes, that could be a viable solution.