You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Roper, John" <Jo...@iOra.com> on 2001/03/30 17:50:33 UTC

Possible problem with exception handling on Win32 platform

Hi,

We had a problem in part of our code with Microsoft's global optimisation in
Visual C++ v6.0. Through a review of the modules that we use in our product
it became apparent that Xerces and Xalan may also suffer from this problem.
There's a knowledge base article about the problem as it relates to
exception handling (Knowledge base ID: Q247203):

BUG: Try/Catch Block May Fail when Global Optimizations (/Og) Are Enabled 

----------------------------------------------------------------------------
----
The information in this article applies to:

Microsoft Visual C++, 32-bit Editions, version 6.0

----------------------------------------------------------------------------
----

SYMPTOMS
When trying to build an application that uses C++ exception handling, with
global optimizations enabled, the catch handler within the try/catch block
may not catch any of the exceptions that are thrown by the instructions in
the try block. See the "More Information" section below for details. 

CAUSE
The optimizer optimizes the try/catch block incorrectly. 

RESOLUTION
Here are the two ways to work around this problem:

Disable global optimizations on a function-by-function basis using the
optimize pragma with the "g" option. /Og- disables global optimization on a
file-by-file basis.

Use the asynchronous exception handling model by specifying the /EHa
compiler option. 

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at
the beginning of this article.

As the article says, the bug may occur when 'global optimisations' are
selected and can result in mis-application of catch blocks.  All Xerxes and
Xalan projects appear to use /O2 which includes global optimisations as part
of a composite switch. Workaround is to et /EHa (async exception handling).
I suggest adding this flag to all Xerces and Xalan projects.

Best Regards
John Roper
iOra Ltd.

www.iOra.com

Re: Possible problem with exception handling on Win32 platform

Posted by Christian Aberger <xm...@Aberger.at>.
Hi, 

Investigating it more, I am not sure any more that it is a bug in the compiler.
It might be a bug in this knowledgebase article, I don't know if there is a well
defined behaviour for that case. 

When you look at the sample code in this article it uses an uninitialized
pointer as an argument to dynamic_cast<>. 

In Latin one would say "ex falso quod libet". Maybe it can be translated to
English (which is also a foreign language to me) as "garbage in, garbage out".

An stl exeption (bad_cast) is raised if the type of the casted object is invalid
for that case. But to have a type, the object must have a valid pointer or
be NULL, not a pointer to invalid memory. I cannot see why the exception should
be caught at all, it is simply wrong code that causes an access violation isn't
it ?  The dynamic_cast looks up the vtable that the invalid pointer points to. I
am not sure what the standard says about a "catch(...)" in that case which here
also does not help.

wfR ChrisA

On Fre, 30 M�r 2001 you wrote:
> Hi,
> 
> We had a problem in part of our code with Microsoft's global optimisation in
> Visual C++ v6.0. Through a review of the modules that we use in our product
> it became apparent that Xerces and Xalan may also suffer from this problem.
> There's a knowledge base article about the problem as it relates to
> exception handling (Knowledge base ID: Q247203):
> 

Re: Possible problem with exception handling on Win32 platform

Posted by Christian Aberger <xm...@Aberger.at>.
Thanks for that mail ! Don't know if it has also to do with Xalan, but yes, I
propably I had such a problem. In a project porting an open source C++ SOAP
implemenation that uses Xerces to windoze I experienced crashes that I could
not reproduce in debug builds. The only difference I found by trial and error
was the optimizer settings (in my code). I had no crash after disabling
optimation. I already forwarded this article and your comment below it to this
mailing list also.

Thanks for info.

wfR ChrisA

 > 
> We had a problem in part of our code with Microsoft's global optimisation in
> Visual C++ v6.0. Through a review of the modules that we use in our product
> it became apparent that Xerces and Xalan may also suffer from this problem.
> There's a knowledge base article about the problem as it relates to
> exception handling (Knowledge base ID: Q247203):
> 
> BUG: Try/Catch Block May Fail when Global Optimizations (/Og) Are Enabled 
> 
> ----------------------------------------------------------------------------
> ----
> The information in this article applies to:
> 
> Microsoft Visual C++, 32-bit Editions, version 6.0
> 
> ----------------------------------------------------------------------------
> ----
> 
> SYMPTOMS
> When trying to build an application that uses C++ exception handling, with
> global optimizations enabled, the catch handler within the try/catch block
> may not catch any of the exceptions that are thrown by the instructions in
> the try block. See the "More Information" section below for details. 
> 
> CAUSE
> The optimizer optimizes the try/catch block incorrectly. 
> 
> RESOLUTION
> Here are the two ways to work around this problem:
> 
> Disable global optimizations on a function-by-function basis using the
> optimize pragma with the "g" option. /Og- disables global optimization on a
> file-by-file basis.
> 
> Use the asynchronous exception handling model by specifying the /EHa
> compiler option. 
> 
> STATUS
> Microsoft has confirmed this to be a bug in the Microsoft products listed at
> the beginning of this article.
> 
> As the article says, the bug may occur when 'global optimisations' are
> selected and can result in mis-application of catch blocks.  All Xerxes and
> Xalan projects appear to use /O2 which includes global optimisations as part
> of a composite switch. Workaround is to et /EHa (async exception handling).
> I suggest adding this flag to all Xerces and Xalan projects.
> 
> Best Regards
> John Roper
> iOra Ltd.
> 
> www.iOra.com
-- 
wfR ChrisA