Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't know where exception was thrown using google-test

We are using Google Test as our C++ unit testing framework. But I ran into a painful situation and don't know how to deal with.

Basically, when there is an uncaught exception in the code, I got the following error message printed in the console and get a FAILED. Obviously, the exception is captures by google test. However, I have no information at all where is the exception was throw.

unknown file: error: SEH exception with code 0xc000005 thrown in the test body.

What I can do is debug and step through the code and I will eventually figure out where the problem is. But this is not very efficient as the project is big.

I want the debugger to stop at the line of uncaught exception and give me a nice call stack. Is there any settings in google test that I don't know of? Any other work around or suggestions will be very much appreciated.

Edit: I am looking for something like the following under Windows enter image description here

Finally according to the answers, I found this settings for visual studio and everything works as the way I want now :) enter image description here

like image 954
Yuchen Avatar asked May 14 '15 14:05

Yuchen


3 Answers

At work the approach I use is to run only the failing testcase using gdb like so:

gdb /path/to/test
catch throw
r --gtest_filter='Test.Testcase' --gmock_verbose=info
bt

With visual studio, I suspect you should be able to start your binary with arguments as above, and set a breakpoint to any throw, then take a look at the backtrace.

like image 165
Matthias Vegh Avatar answered Sep 19 '22 03:09

Matthias Vegh


An SEH Exception is NOT a C++ exception.

It is a windows exception that is throw outside of the standard C++ framework for exception handing (there is a different syntax for catching them).

The best way to find the location is to run this inside DevStudio. Its been a while but I am sure DevStudio has an option to break when SEH exception is thrown. Just turn this on and your debugger will stop at the throw point and allow you to debug.

See: https://msdn.microsoft.com/en-us/library/d14azbfh.aspx

As noted by @MatthiasVegh you should pass the name of the test as well so you don't have to run through all the tests.

like image 25
Martin York Avatar answered Sep 21 '22 03:09

Martin York


That is not possible since C++ doesn't keep stack trace in the exception object and even if gtest had some smart catching mechanism it would have no means to know where the exception came from. The best you can do is to store some information in the exception yourself and check it in the test case.

like image 37
ixSci Avatar answered Sep 21 '22 03:09

ixSci