Click to See Complete Forum and Search --> : structured exception


George2
January 20th, 2008, 09:03 AM
(I wrongly posted this question to C++ non-Visual C++ sub-forum, according to other people's suggestion, here is more appropriate)

Hello everyone,


I am learning structured exception from,

http://msdn2.microsoft.com/en-us/li...409(VS.85).aspx

I read a couple of links from MSDN, but still confused what is structured exception, what is the differences between structure exception and our normal C++ exception, like bad_alloc and various user define exception?


thanks in advance,
George

krush_ter
January 22nd, 2008, 05:25 AM
Hi,

Structured exception handling (SEH) is a base mechanism for exception handling, that is supported by Windows operating system. You can use them only in Windows environment.

C++ exceptions are the part of C++ language, so they work in any operating system. In Windows, C++ exceptions are realized using SEH mechanism.

SEH is a very powerful stuff, but you should use c++ exceptions instead if you want to write portable applications.

Best regards,
Vladimir.

George2
January 22nd, 2008, 05:35 AM
Thanks Vladimir,


I have made some further study and I want to share my points here to let you review and comment.

http://members.cox.net/doug_web/eh.htm

From section Q2, I found two mistakes I made before.

1. Previously I think currently in Visual Studio 2005 or 2008, we could only use C++ exception, but now I think we can switch to let compile generate code either throws structured exception or C++ exception by using /EHa or /EHs, right?

2. Previously, I think catch(...) can only catch C++ exception, but after learning, I think catch(...) can also catch structured exception. Right?

Hi,

Structured exception handling (SEH) is a base mechanism for exception handling, that is supported by Windows operating system. You can use them only in Windows environment.

C++ exceptions are the part of C++ language, so they work in any operating system. In Windows, C++ exceptions are realized using SEH mechanism.

SEH is a very powerful stuff, but you should use c++ exceptions instead if you want to write portable applications.

Best regards,
Vladimir.


regards,
George

krush_ter
January 22nd, 2008, 09:19 AM
Well, it is very interesting article.
I did not know about Visual studio bug with /EHs flag.

1. In case of synchronous exception model (/EHs) catch(...) instruction don't must to catch SEH exceptions. But due to bug of VS untill 2003 version, it does. That is not good. So, you can not distinguish legal catch(...) when you throwed exception in your code from illegal situation when your code made general protection fault (e.g. dereferenced null pointer). This must be available in asynchronous exception model (/EHa) only.
But synchronous model in VS 2005/2008 works correctly and when your application makes general protection fault, operating system terminates it.
In case of asynchronous exception model, VS2005/2008 converts SEH into C++ exception and passes it to catch(...) code block. So the difference of /EHa from /EHs is in converting SEH exceptions into C++ exceptions in case of catch(...) code block.

2. Yes, in case of /EHa flag or in case of buggy compiler as 5.0, 6.0 and 2003, catch(...) will catch SEH exceptions.

Vladimir.

krush_ter
January 22nd, 2008, 09:34 AM
I found that the /EHs catch(...) bug is corrected in VS 2003 Service Pack 1.

George2
January 22nd, 2008, 09:24 PM
Thanks Vladimir,


I am confused about your below comments. You mean even if we enable /EHsc for the synchronized exception model, Visual Studio will cnoverted errors like access violation into C++ exception and let us use catch(...) handle it? Correct me if I am wrong to understand your points.


But synchronous model in VS 2005/2008 works correctly and when your application makes general protection fault, operating system terminates it.
In case of asynchronous exception model, VS2005/2008 converts SEH into C++ exception and passes it to catch(...) code block. So the difference of /EHa from /EHs is in converting SEH exceptions into C++ exceptions in case of catch(...) code block.

Vladimir.


regards,
George