|
Hi Ben, I've just been struggling with C++'s rather slack exception system. I was doing this: const XrlArgs& in; // a parameter
try {
uint32_t delay;
in.get("boo_delay", delay);
...
} catch (const XrlArgs:XrlAtomNotFound& e) {
// Get other arguments.
}
So obviously I was getting XrlAtomNotFound exceptions that were
killing the process, and I added the try-catch to intercept them -
but it wasn't working. Traces showed that the exception was
certainly happening on [in.get], but the catch block never executed.The method I'm calling doesn't declare the exception I'm trying to catch: void get(const char* n, uint32_t& t) const throw (BadArgs);That method calls this one: const uint32_t&
XrlArgs::get_uint32(const char* name) const throw (BadArgs)
{
try {
return get(XrlAtom(name, xrlatom_uint32)).uint32();
} catch (const XrlAtom::NoData& e) {
xorp_throw(BadArgs, e.why());
} catch (const XrlAtom::WrongType& e) {
xorp_throw(BadArgs, e.why());
}
}
…and you can see that that code calls get(const XrlAtom&), which
is declared to throw XrlAtomNotFound. But get_uint32 doesn't catch
that exception itself. According to this (under "Exception
Specifications"):<http://4thmouse.com/mystuff/articles/UsingExceptionsEffectively.html> …the uncaught exception simply terminates the program immediately; not even an unwinding of the stack, it seems! Two possible solutions are obvious: either propagate the declaration of XrlAtomNotFound, or catch it in this and related functions, and throw a BadArgs instead. I suppose the latter would be much less disruptive. Incidentally, if the [get] call inside get_uint32 can only throw XrlAtomNotFound, can either of the existing catch clauses ever execute? Cheers, Steven |
_______________________________________________ Xorp-hackers mailing list [email protected] http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/xorp-hackers
