/Og causes intermittent omission of try..catch block 
Author Message
 /Og causes intermittent omission of try..catch block

Does the problem exist when using __try __except() bloc in pure C code ? (I
did'nt see it but in case of...)


Fri, 26 Oct 2001 03:00:00 GMT  
 /Og causes intermittent omission of try..catch block

Quote:
> 1. In VC5 and VC6 release builds that use the default -GX option,
catch(...)
> won't catch the Win32 structured exception in the code above. You
have to
> remove -GX and use -EHa instead. However, in VC6, if the tried code
occurred
> in another function defined in another translation unit, a release
build
> that used -GX *would* catch the SE. In VC5, the function could occur
in the
> same translation unit as the function containing the try block. The
reason
> for this is that the optimizer will elide the try/catch machinery if
it can
> determine the tried code can't throw a C++ exception, and VC6's
optimizer is
> a little smarter than VC5's in this regard.
> 2. You shouldn't want catch(...) to ever catch non-C++ exceptions.

Thanks for the reply.  As you know, the problem still occurs when using
the "_set_se_translator" for se's (which was stripped out from the test
case to get it smaller).

The real issue is that -GX is the default when it is the least safe, -
EH isn't in the GUI, and that the docs on -EH are poor.

This is what I received from MS tech support in case it helps anyone
else.
===============================================

As you asked me for here is some more explanation about /EH switch:
The project settings dialog in Developer Studio only turns on and off
/GX
which is equivalent to /EHsc. If you are adding /EHc-, then you have /GX
turned set. If you need a different option for exception handling
(which you
do), turn off exception handling in the settings dialog and type in the
setting you need in the Project Options box.

/EHs means that the compiler can assume that only exceptions thrown
with the
C++ throw syntax are expected to be caught.

/EHa means that the compiler can assume that all exceptions are
expected to
be caught.

/EHc adds some additional flexibility. /EHc means that the compiler can
assume that extern "C" functions won't throw a catchable exception.

/EHs is equivalent to /EHsc. This means that the compiler can assume
that
extern "C" functions won't throw a catchable exception and that the only
catchable exceptions are thrown with the C++ throw syntax. This is the
option
you had and it clearly didn't allow you to catch the exceptions you
wanted
to catch.

/EHsc- means that the compiler can assume that extern "C" functions can
throw catchable exceptions, but the C++ code with only generate
exceptions
via the C++ throw syntax. If you dereference a null pointer in an
extern "C"
function, you can catch that exception. If you dereference a null
pointer in
your C++ code, you can't catch that exception.

/EHa means that the compiler can assume that any instruction may cause a
catchable exception. /EHc has no effect since the compiler has to assume
that any instruction can cause an exception.

If you want to catch exceptions (such as an access violation) that can
occur
without a C++ throw, then you must use /EHa.

Does this clear things up?

--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---



Fri, 26 Oct 2001 03:00:00 GMT  
 /Og causes intermittent omission of try..catch block

Quote:

>Does the problem exist when using __try __except() bloc in pure C code ? (I
>did'nt see it but in case of...)

I wouldn't think so. __try/__except deal in Win32 structured exceptions,
which, by definition, include things like access violations.

--
Doug Harrison

Visual C++ MVP



Fri, 26 Oct 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. The if ~ else block in try~catch block

2. Optimizer ignores try-catch block

3. try catch block

4. Help -Try block causing conditon to evaluate incorretly

5. does atl support try..catch block?(empty inside)

6. Overhead of try-catch blocks?

7. nested try/catch block and _set_se_translator

8. try{} catch{} block and Global Optimization

9. Error processing using try-catch blocks

10. TRY-CATCH vs. try-catch

11. can I nest try/catch blocks?

12. try/catch VS TRY/CATCH

 

 
Powered by phpBB® Forum Software