User defined SEH with Release build

G

Guest

Hi guys,

I created a user-defined SEH by following Crash Course SEH article by Matt
Pietrek. When building the app in Debug mode, it has no problem catching
exception and entering the user defined hanlder. In Release mode, however,
the app would just crash at the point where the exception occurs.

Why is that? Is there any way to solve this?

Thanks in advance,
Johnny
 
W

William DePalo [MVP VC++]

Johnny said:
I created a user-defined SEH by following Crash Course SEH article by Matt
Pietrek. When building the app in Debug mode, it has no problem catching
exception and entering the user defined hanlder. In Release mode,
however,
the app would just crash at the point where the exception occurs.

Why is that? Is there any way to solve this?

It may be the optimizer that is biting you.

Are you translating structured exceptions to C++ "typed" exceptions with
_set_se_translator()? If so, what is probably happening is that the compiler
sees no way that the C++ code could throw an exception so it just goes ahead
and removes the try / catch stuff.

If that's your problem you can "fix" it by compiling with the /EHa switch.

There is quite a lot to say on this subject and Doug does it best here:

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

Regards,
Will
 
G

Guest

William DePalo said:
Are you translating structured exceptions to C++ "typed" exceptions with
_set_se_translator()? If so, what is probably happening is that the compiler
sees no way that the C++ code could throw an exception so it just goes ahead
and removes the try / catch stuff.

If that's your problem you can "fix" it by compiling with the /EHa switch.

There is quite a lot to say on this subject and Doug does it best here:

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

Regards,
Will

Thanks for the reply, William,

I have tried the /Eha switch and still got the same problem.
I did not use the _set_se_translotr() , instead, using the assemly code to
directly replacing _EXCEPTION_REGISTRATION structure. It is a method
described in the Matt Pietrek's article and is commonly seen and used on the
net.

However, I still think it's a compiler related issue, as the method would
work fine with VC6 compilation (both Debug and Release) and not in VC 2005
(only Debug mode works)

P.S.
You can find Matt Pietrek's article here:
http://www.microsoft.com/msj/0197/Exception/Exception.aspx

Any more ideas?
Thanks again,
Johnny
 
C

Carl Daniel [VC++ MVP]

Johnny said:
Thanks for the reply, William,

I have tried the /Eha switch and still got the same problem.
I did not use the _set_se_translotr() , instead, using the assemly
code to directly replacing _EXCEPTION_REGISTRATION structure. It is
a method described in the Matt Pietrek's article and is commonly
seen and used on the net.

However, I still think it's a compiler related issue, as the method
would work fine with VC6 compilation (both Debug and Release) and not
in VC 2005 (only Debug mode works)

P.S.
You can find Matt Pietrek's article here:
http://www.microsoft.com/msj/0197/Exception/Exception.aspx

Note the ancient date on the article - it's nearly 10 years old.

I have a suspicion that your attempt at defining an exception record is
running afoul of new security measures that have been put into the
compiler/runtime libraries to block exception-based attack vectors. I don't
know any details of what's been changed, but I know that changes were made -
starting in VC7, I think. Have you tried VC7 or 7.1, or are VC6 and 8 your
only data points?

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top