unhandled exception? unknown file:Failure in SetUp()

14,286 views
Skip to first unread message

Katy Huff

unread,
Mar 15, 2013, 5:12:33 PM3/15/13
to googletes...@googlegroups.com
Hi all,

I'm struggling with some kind of unhandled exception or something that is thrown in SetUp() in my gtest code here : 

The tests give :

[----------] 13 tests from STCThermalTest
[ RUN      ] STCThermalTest.initial_state
unknown file: Failure
C++ exception with description "vector::_M_range_check" thrown in SetUp().
[  FAILED  ] STCThermalTest.initial_state (14 ms)
....

If I track it down in gdb, the crash backtraces to this line (29) and I get back to a line initializing the MatDataTablePtr (a boost::shared_ptr)... but not to anything throwing an out of range exception (which is where "vector::_M_range_check" appears to come from).

The trouble isn't just the MatDataTablePtr either. Commenting that out, the same thing happens on line 35 with another boost shared ptr. 

Maybe it's just some trouble in my code and the way I'm handling these particular shared pointers, but these have not given me trouble in any analogous places in my code, so it's confusing. Anyway, since I've now been looking at this problem for almost an entire day, I thought maybe it was time to see if you guys would have some insight. What's the current method of debugging the gtest "unknown file: Failure" unhandled exception behavior in SetUp() ?

Katy

--
http://katyhuff.github.com

Katy Huff

unread,
Mar 15, 2013, 5:26:11 PM3/15/13
to googletes...@googlegroups.com
P.S. For clarity, since that link will point to other code if I push
anything, the code I'm talking about is below, and line 29 is
"mat_table_=MDB->table(mat_);"

// STCThermalTests.cpp
#include <deque>
#include <map>
#include <gtest/gtest.h>

#include "STCThermalTests.h"
#include "ThermalModelTests.h"
#include "CycException.h"
#include "Material.h"
#include "MaterialDB.h"
#include "XMLQueryEngine.h"

using namespace std;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - -
void STCThermalTest::SetUp(){
// set up geometry. this usually happens in the component init
r_four_ = 4;
r_five_ = 5;
point_t origin_ = {0,0,0};
len_five_ = 5;
geom_ = GeometryPtr(new Geometry(r_four_, r_five_, origin_, len_five_));

// other vars
k_th_ = .1; // ___ @TODO worry about units
spacing_ = .1; // ___ @TODO worry about units
alpha_th_ = .1; // ___ @TODO worry about units
time_ = 0;
mat_ = "clay";
mat_table_=MDB->table(mat_);

// composition set up
u235_=92235;
u_=92;
one_mol_=1.0;
test_comp_= CompMapPtr(new CompMap(MASS));
(*test_comp_)[u235_] = one_mol_;
test_size_=10.0;

// material creation
Cs135_ = 55135;
Cs137_ = 55137;

hot_comp_ = CompMapPtr(new CompMap(MASS));
(*hot_comp_)[Cs135_] = 1000;
(*hot_comp_)[Cs137_] = 1000;
cold_comp_ = CompMapPtr(new CompMap(MASS));
(*cold_comp_)[Cs135_] = 1;

hot_mat_ = mat_rsrc_ptr(new Material(hot_comp_));
cold_mat_ = mat_rsrc_ptr(new Material(cold_comp_));

// test_stc_thermal model setup
stc_ptr_ = STCThermalPtr(initThermalModel()); //initializes stc_ptr_
therm_model_ptr_ = boost::dynamic_pointer_cast<ThermalModel>(stc_ptr_);
stc_ptr_->set_mat_table(mat_table_);
stc_ptr_->set_geom(geom_);
default_stc_ptr_ = STCThermalPtr(STCThermal::create());
default_therm_model_ptr_ =
boost::dynamic_pointer_cast<ThermalModel>(default_stc_ptr_);
default_stc_ptr_->set_mat_table(mat_table_);
.....
--
http://katyhuff.github.com

Keith Ray

unread,
Mar 15, 2013, 5:49:43 PM3/15/13
to Katy Huff, googletes...@googlegroups.com
Can you set a breakpoint on exception-throwing?

Did you try "valgrind" or a malloc-debugging tool?

Try commenting out all but one of the member variables of STCThermalTest - does it run OK? (repeat for each member variable.)

Is it possible that somehow you pass a raw pointer into two or more shared_ptr instances, and thus it deletes an object twice?

C. Keith Ray
https://dl.dropbox.com/u/686328/keith_ray_resume.pdf
I'm seeking a MacOSX/iOS Objective-C / C++ Job. Can you help?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Katy Huff

unread,
Mar 15, 2013, 6:02:30 PM3/15/13
to Keith Ray, googletes...@googlegroups.com
On Fri, Mar 15, 2013 at 4:49 PM, Keith Ray <keit...@gmail.com> wrote:
> Can you set a breakpoint on exception-throwing?
>

No, it's definitely being thrown from within boost.

> Did you try "valgrind" or a malloc-debugging tool?
>

I did, but this too leads me back to the boost internals.

> Try commenting out all but one of the member variables of STCThermalTest - does it run OK? (repeat for each member variable.)
>

I'll try this now.

> Is it possible that somehow you pass a raw pointer into two or more shared_ptr instances, and thus it deletes an object twice?
>

Very possible. Thanks for the suggestions. I'll let you know how it goes.
--
http://katyhuff.github.com

Katy Huff

unread,
Mar 16, 2013, 11:36:30 AM3/16/13
to Keith Ray, googletes...@googlegroups.com
Thanks! This is all fixed now, and was of course not the fault of
googletest at all. Your suggestions helped a lot for tracking it down
though, Keith. GDB was really failing me in that setup() environment,
and I'd never have tracked it down without the variable
commenting/uncommenting strategy. Thanks!

Anyway, if you're curious, it turns out it wasn't a misuse of shared
pointers, just sloppy sql querying on my part. The problem was
ultimately a moment where I was accessing an empty sql query result.
Since I didn't wrap the query with a try/catch for the empty result
case, an out_of_range exception was getting tossed all the way back up
to an object initialization in setup.

Thanks!
Katy
--
http://katyhuff.github.com

Keith Ray

unread,
Mar 16, 2013, 12:02:09 PM3/16/13
to Katy Huff, googletes...@googlegroups.com
Glad I could help!

--
C. Keith Ray
* I'm seeking a MacOSX/iOS Objective-C/C++ Job. Can you help?
* https://dl.dropbox.com/u/686328/keith_ray_resume.pdf
* http://agilesolutionspace.blogspot.com/
Reply all
Reply to author
Forward
0 new messages