
Throwing exceptions in ATL dll with optimize for SPEED causes Access Violation
Hello,
Thanks for the reply.
My understanding of that limitation is that because _alloca allocates on the
stack and should not be called directly from a try-catch block. It is
however OK to call it from a function which is called from the try-catch
block. In this case, the call stack looks as follows:
AtlSetErrorInfo
AtlReportError inline calls _alloca
Error non-inline
Function calling error in catch block
I realize that AtlReportError is inlined away on optimize for speed, but
there is still the Error() function which would provide the necessary stack
Thanks again.
Prasenjit
Quote:
> The only thing I can think of is that Error() uses AtlReportError() which
> uses A2COLE() which uses (ultimately) A2W which uses _alloca() and that is
> not supposed to be used in a try/catch block..
> Check out KB article
> PRB: Calling String Conversion Macros in Catch Block Causes AV
> ID: Q198009 .. That explains the problem..
> That might be the problem. To see if it helps, convert that string
manually
> into a wide char using L"" and see if that works..
> --
> Girish Bharadwaj
> > Hello,
> > We have generated an ATL COM DLL (using the wizard) in which we throw
and
> > catch exceptions (C++) and return a COM Error as follows:
> > try {
> > int i = 20;
> > throw i;
> > }
> > catch (int & e) {
> > return Error("I caught an exception");
> > }
> > return S_OK;
> > This code compiles but causes access violation if we use the compiler
> > optimization to maximize speed. No problem if optimized for size.
> > The access violation occurs as soon as we return the "Error" and not at
> > throw time.
> > I was wondering if anyone could shed light on this.
> > Thanks
> > Prasenjit