Disabling Exception Handling

VC++ 6.0

I can't seem to disable exception handling.  I have a try / catch block and whenever I hit my exception control goes to my catch(...) handler.

I do not have /GX set.  I am building using the IDE.  (When I set /GX- in Project Settings the IDE just removes the switch...supposedly GX- is the default.)

Oh, and yes;  as expected, when I compile with E.H. disabled I get a warning that my unwind semantics are not enabled. 

My program should simply crash with E.H. turned off.

QUESTION:  How do I get VC++ E.H. to really turn off

Thanks.

(Legitamate email, not spam, welcome at les.h.clark@baesystems.com.NoSpam w/o the 'NoSpam', of course)




Answer this question

Disabling Exception Handling

  • Rambo

    One more "twist" to to this issue: up until the-soon-to-be-released Visual C++ 2005 catch (...) would catch SEH exceptions: this caused problems like what your have reported above. With Visual C++ 2005 catch (...) will not catch SEH exceptions.

    Also the comment from Ismail is not quite correct. The correct statement of the rule is that you can't have C++ objects that require unwinding on the stack with-in a __try block.

    class A {
    };

    class B {
    public:
       ~B();
    };

    void f()
    {
       __try {
          A a;   // OK
          B b;   // Error
       }
       __except (1) {
       }
    }


  • RMcGill

    If you turn off exception handling, it turns of "C++ exceptions", not Win32 exceptions, which should be in __try/__except/__finally blocks. You need to use Structured Exception Handling mechanism to deal with them. SEH cannot be used together with C++ exceptions, because it doesn't satisfy C++ exception requirements, AFAIK. This is why you need to deal with stack unwinding separately from SEH.

    If you have turned off your "C++ exception handling", do not use try-catch, you need __try/__except, and move those automatic objects into a function. See below:

    class CMyClass
    {
    /* ... */
    };

    void SEHFriendlyCppFunction();

    int foo()
    {
         __try
         {
               // CMyClass cls; // error - you can't have a C++ object on the stack when using SEH.
               SEHFriendlyCppFunction();           
         }
         __except(HandleWin32Exception())
         {
         }
         __finally
         {
         }
    }

    void SEHFriendlyCppFunction()
    {
         CMyClass cls;
         cls.Foo();  // hypothetically, this function can throw a Win32 exception...
    }  // stack unwinding happens here, not in SEH block.


    Ismail

  • pgupta

    Thanks Jonathan!

    Will we be able to get (win32) exception information the way we normally do in __try/__except case

    Ismail


  • goozbee

    Yes: the only thing that has changed is that catch (...) not longer catches  SEH exceptions: nothing has changed with respect __try/__except.

  • Disabling Exception Handling