CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2000
    Location
    Dallas, Texas
    Posts
    62

    Can't catch Access Violation!

    Ok,

    I've read through several threads on using SEH to catch exception that would normally not be caught by your standard try-catch blocks.

    Using a basic setup, I cannot catch an Access Violation occuring in an ActiveX control that I am deleting.

    Code:
    static void my_translator(unsigned code, EXCEPTION_POINTERS *)
    {
         throw code;
    }
    
    
    // called in dialog constructor:
    _set_se_translator(my_translator);
    
    
    CMydialog::OnCloseConnection()
    {
         try
         {
               delete m_pWA;
        }
        catch(unsigned code)
        {
             AfxMessageBox("Testing:  caught access violation");
        }
    }
    Program crashes, my translator is never called. What am I missing?

  2. #2
    Join Date
    Jun 2003
    Location
    Bucharest, Romania
    Posts
    529

    Re: Can't catch Access Violation!

    that kind of catch is not working. See my post (or better the answers) here
    mainly use SetUnhandledExceptionFilter good luck!
    Last edited by chi_luci; January 26th, 2005 at 09:21 AM.
    Help me help you ... rate this article if any good!

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

    Re: Can't catch Access Violation!

    You can catch Structured Exceptions using catch(...).

    Some conditions to be aware of...

    1) The exception is occuring in another thread which is being started [your activeX call]. Exceptions are "thread-safe" but they are not propagated to other threads.

    If you install a SE translator it must be done on a per thread bases. The SetUnhandledExceptionFilter(...) is a global handler.

    2) Later versions of vc++ [8.0] the exception handling was changed such that you have to apply the /EHa switch to denote that you want to catch structured exceptions via a catch(...)

    3) If you have faulty exception handling logic such as generating an exception out of a dtor of an local object being destructed while procesing a previous exception.

    In the end you need to run your code under a debugger and find out why you are generating an exception in the ActiveX code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured