catch rethrown exception in gtest (using google's gtest),

D

dust

Hi,

I'm a testng a function func(), a member function of class A, defined
in A.cpp. But while creating object of A, an exception is thrown in
constructor.
Here is gdb output:

(gdb) bt
#0 0x00504eff in raise () from /lib/tls/libc.so.6
#1 0x00506705 in abort () from /lib/tls/libc.so.6
#2 0x0019c4f7 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0x0019c544 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0x0019c6b6 in __cxa_throw () from /usr/lib/libstdc++.so.5
#5 0x0804b530 in A (this=0x9be8390) at path/to/A.cpp:381

As this obect is being created in my test case, I put the object
creation in try catch block as
try
{
A obj;
}
catch (int res) { }


When I compiled and run the test, this time an exception is thrown in
Test body itself. Here is the gdb output:

(gdb) bt
#0 0x00cd2eff in raise () from /lib/tls/libc.so.6
#1 0x00cd4705 in abort () from /lib/tls/libc.so.6
#2 0x00eca4f7 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0x00eca544 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0x00eca71c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5 0x08054103 in myTest_Test::TestBody (this=0x868b230) at A.cpp:13

The difference between 2 output is at frame #2, in 1st case it is
__cxa_throw (), and in 2nd case it is __cxa_rethrow ().

Please help me how to catch the exception generated from my test case.
 
D

dust

(gdb) bt
#0  0x00cd2eff in raise () from /lib/tls/libc.so.6
#1  0x00cd4705 in abort () from /lib/tls/libc.so.6
#2  0x00eca4f7 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3  0x00eca544 in std::terminate () from /usr/lib/libstdc++.so.5
#4  0x00eca71c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5  0x08054103 in myTest_Test::TestBody (this=0x868b230) at A.cpp:13

Sorry.. This is A_test.cpp and not A.cpp.
 
A

Alf P. Steinbach /Usenet

* dust, on 24.11.2010 06:24:
Hi,

I'm a testng a function func(), a member function of class A, defined
in A.cpp. But while creating object of A, an exception is thrown in
constructor.
Here is gdb output:

(gdb) bt
#0 0x00504eff in raise () from /lib/tls/libc.so.6
#1 0x00506705 in abort () from /lib/tls/libc.so.6
#2 0x0019c4f7 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0x0019c544 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0x0019c6b6 in __cxa_throw () from /usr/lib/libstdc++.so.5
#5 0x0804b530 in A (this=0x9be8390) at path/to/A.cpp:381

As this obect is being created in my test case, I put the object
creation in try catch block as
try
{
A obj;
}
catch (int res) { }


When I compiled and run the test, this time an exception is thrown in
Test body itself. Here is the gdb output:

(gdb) bt
#0 0x00cd2eff in raise () from /lib/tls/libc.so.6
#1 0x00cd4705 in abort () from /lib/tls/libc.so.6
#2 0x00eca4f7 in __cxa_call_unexpected () from /usr/lib/libstdc++.so.
5
#3 0x00eca544 in std::terminate () from /usr/lib/libstdc++.so.5
#4 0x00eca71c in __cxa_rethrow () from /usr/lib/libstdc++.so.5
#5 0x08054103 in myTest_Test::TestBody (this=0x868b230) at A.cpp:13

The difference between 2 output is at frame #2, in 1st case it is
__cxa_throw (), and in 2nd case it is __cxa_rethrow ().

Please help me how to catch the exception generated from my test case.

Possibly some feeble-minded person will post an "answer" containing three dots,
and you will think that's great.

The rest of us are, however, more concerned with correctness than local
symptom-fixes, and, note: we are not telepaths, sorry.

So, post the relevant code.

See the relevant FAQ item for advice about posting a question about code that
does not work.

Follow that advice.


Cheers & hth.,
 
D

dust

* dust, on 24.11.2010 06:24:










Possibly some feeble-minded person will post an "answer" containing three dots,
and you will think that's great.

The rest of us are, however, more concerned with correctness than local
symptom-fixes, and, note: we are not telepaths, sorry.

So, post the relevant code.

Posting exact code might be a violation of copyright. So I have
replaced all paths with "path/to/..." and class name to generic name,
A.
However my test case is written by me and hence not a violation. So I
have posted the exact test body (try, catch block).

The main issue here is "exception re-thrown in catch block". Please
try to suggest a generic solution.
See the relevant FAQ item for advice about posting a question about code that
does not work.

please send a link to that FAQ.
 
I

Ian Collins

Posting exact code might be a violation of copyright. So I have
replaced all paths with "path/to/..." and class name to generic name,
A.
However my test case is written by me and hence not a violation. So I
have posted the exact test body (try, catch block).

The main issue here is "exception re-thrown in catch block". Please
try to suggest a generic solution.

You don't show any code that re-throws exceptions.
please send a link to that FAQ.

See the welcome message posted to this group every few days.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top