CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    19

    Catching Access Violation Exception

    First off - i know I shoudln't be trying to catch this type of exception.

    I'm using a dll that I don't have the code for. It being called in a windows form in c#. All I want to have happen is if the exception occurs, kill the application without any kind of dialog popping up. This is what I'm using now, but it's not catching it.

    static void Main()
    {
    try
    {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
    #if DEBUG
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
    #else
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
    #endif
    }
    catch (AccessViolationException ex)
    {
    Application.Exit();
    }
    }

    Any ideas how to do this? All I want to have happen is the application die a nice quiet death if the exception occurs.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Catching Access Violation Exception

    Ok.

    A few questions:

    1. What kind of dll are you using? Is it an unmanaged/native dll? Is it a .NET dll that has some unsafe code? How do you know that the error is due to the dll you are using (This might be obvious to you but there was no detail in your post to link the two categorically).

    2. How do you are getting an access violation by the way?

    3. Have a look at this link and this as well

  3. #3
    Join Date
    Apr 2005
    Posts
    19

    Re: Catching Access Violation Exception

    Thanks for the reply!

    1. The suspect dll is a Scada system written in unmanaged C++. It's not a commercially available system. I have no direct information that this is the problem, however the people I talk to that work for the same company but in other countries all point to this system as it is known to have problems. But I don't have any evidence of this myself.

    2. My application is supposed to be up all the time. I only get this exception once every few days. I left Visual Studio running in debug and it showed the exception in my program.cs main function (shown above). When I run it in release mode, an error box pops up asking if I want to break or continue. It also says theres an access violation and then lists all the dlls loaded, but from what I could see, it didn't specify which dll caused the violation.

    3. I added a catch to the main loop for NullReferenceException. Now I have to wait and see...

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