[bind10-dev] proposal: catching exceptions in run_unittests.cc:main()
JINMEI Tatuya / 神明達哉
jinmei at isc.org
Tue Jan 25 00:23:45 UTC 2011
At Sat, 22 Jan 2011 10:31:55 +0100,
Michal 'vorner' Vaner <michal.vaner at nic.cz> wrote:
> There's another regression on my system. When running under GDB and the
> exception is thrown (and uncaught), GDB stops at the point when the exception is
> thrown, before unwinding the stack, therefore all the reasons why it was thrown
> and where is still clearly visible. With your proposal, it would show at the
> bottom of this block, which already has no information.
Ah, you're right. I didn't notice that in my trial experiments.
> So, it would be nice to have a library with main inside we could just link and
> it could turn off/on the check for g++/anything else.
Okay, but for "why and where", there may be a third way. In most
cases what's thrown is our internal exceptions derived from the
isc::Exception class. It contains the information of file name + line
number where the exception is thrown, so we could print this
information for isc::Exception's (we may or may not ignore other
std::exception's, and may or may not do so depending on the compiler
type). If you want a full stack trace starting from the point where
the exception is thrown, however, this cannot be a workaround.
> But aside for these implementation details, I think it is a good idea. Anyway, I
> would like a practice where any tested code would still be wrapped in some kind
> EXPECT_NO_THROW, one function after another.
I've noticed the EXPECT_NO_THROW practice in tests you wrote.
Actually, this approach has the same problem and I've been suffering
from that, too:-) EXPECT_NO_THROW only reports it throws "something"
and obscures what's wrong:
query_unittest.cc:330: Failure
Expected: responseCheck(response, Rcode::NOERROR(), AA_FLAG, 0, 1, 0, __null, soa_txt, __null) doesn't throw an exception.
Actual: it throws
What's the purpose of using EXPECT_NO_THROW, btw? So that you can
still run the rest of the tests (in the same run_unittests program)?
If so, I see the point, and in that case I wonder whether we might
write an additional wrapper:
#define ISC_EXPECT_NO_THROW(test) \
EXPECT_NO_THROW( \
do { \
try { \
test; \
} catch (const isc::Exception& ex) { \
std::cerr << "An exception of class '" << typeid(ex).name() \
<< "' was thrown unexpectedly at " \
<< ex.getFile() << ":" << ex.getLine() << "\n"; \
std::cerr << " what(): " << ex.what() << std::endl; \
throw; \
} catch (...) { \
std::cerr << "An exception is thrown unexpectedly" << std::endl; \
throw; \
} \
} while (false); \
)
---
JINMEI, Tatuya
Internet Systems Consortium, Inc.
More information about the bind10-dev
mailing list