SEH exception with code 0xc0000005 thrown in the test body

32

I am writing a test using GoogleTest for the following class and I am getting the above error.

class Base
{
    // Other Functions;

    CSig objSig[50];
}

The Class CSig is as follows:

class CSig
{
    //... constructor, destructor(empty) and some functions
    CMod *objMod;
    CDemod *objDemod;
}

CSig :: CSig
{
    bIsInitialised = false;

    for (int i=0; i<MAX_NUM; i++)
    {
        PStrokePrev[i] = 0.0;
    }
}

However, when I discard CSig objSig[50], the tests run fine.

What can I do to solve this issue? Also, I need to have CSig objSig[50] in the Base class.

c++
visual-c++
tdd
googletest
asked on Stack Overflow Oct 31, 2012 by chintan s • edited Jan 27, 2018 by honk

8 Answers

33

A SEH (Structured Exception Handling) exception is not a C++-exception that can be handled using c++-language constructs (try-catch) but it is raised from windows itself and points to some fundamental flaw. SEH-exceptions are very annoying because they do not cause normal stack unwinding which can lead to unclosed files or not-unlocked mutexes that should normally cleared by the destructors of the owning object. I have encountered SEH-exceptions when accessing memory that does not belong to the current process so I recommend looking at memory-related instructions in the constructor and destructor of CSig. You can read about SEH, for instance, here

answered on Stack Overflow Oct 31, 2012 by MadScientist
14

The way I just found the problem was that in Visual Studio I went to Debug->Exceptions, and checked everything in the first column. Then run/debug your unit tests, and it will throw an exception on the line that the problem is at. That's where you need to debug/fix it.

answered on Stack Overflow Mar 17, 2015 by Michele
8

I ran into this very problem using GoogleTest with Visual Studio 2010. Our setup involves creating a library for the GoogleTest Frameworks, which is then linked against our individual Unit Tests. I recently updated the Frameworks support and recompiled it from scratch. After doing this, I encountered the exception described above.

After a bit of digging, I discovered that the 'Struct Member Alignment' setting was the culprit:

Project properties > Configuration Properties > C/C++ > Code Generation > Struct Member Alignment

While the Frameworks project had the setting set to 'default', the corresponding Unit Test project had it configured to "1 Byte /Zp1". Once I changed them to have the same alignment, the problem went away.

answered on Stack Overflow Feb 26, 2015 by (unknown user)
3

For me it appeared to be a null reference error. Some method was called on a nullptr and for reasons unclear to me it didn’t fail immediately but just started executing. The SEH error presumably occurred as soon as unallocated memory was accessed. So check for null pointers!

answered on Stack Overflow Feb 8, 2016 by Chiel ten Brinke
1

If you are using Visual Studio 2013, check the Thrown box for Win32 exceptions (specifically access violation) in Debug>Exceptions. This will let you debug which line has the issue. This might be useful since the debugger will not break if your program normally raises other exceptions.

answered on Stack Overflow Oct 19, 2016 by Chaitanya
1

I am having a similar issue and its pertaining to un-initialized variables and running the test in release build. I had a char * un-initialized after which initialized to NULL seems to have fixed the issue.

answered on Stack Overflow Mar 29, 2017 by TrustyCoder • edited Mar 29, 2017 by TrustyCoder
1

destroying null pointer can be a reason. I found out through Visual Studio > Exception > Select All. Then run local windows debugger, it stopped at line where exception occurred.

answered on Stack Overflow Dec 30, 2020 by Ankita Kalra
0

Ran into this problem using msvc in qt. SEH was thrown almost randomly, for no apparent reasons. (read: didn't have any time left to look into it) After NOT finding the right solution and the tests seemed to work for non-windows users, I switched to MinGW which ran the tests normally.

answered on Stack Overflow Dec 13, 2019 by Jax297

User contributions licensed under CC BY-SA 3.0