Hiya Moses,
There are a fair number of exceptions thrown that are not intended to
be caught e.g. Sentence.cpp: 107:
if (!ProcessAndStripXMLTags(line, xmlOptionsList,
m_reorderingConstraint, xmlWalls )) {
const string msg("Unable to parse XML in line: " + line);
TRACE_ERR(msg << endl);
throw runtime_error(msg);
I use them extensively in kenlm for file formatting issues. When an
exception is thrown and nothing catches it (i.e. the stack unwinds past
main), GCC typically prints the type of the exception and the .what()
string. However, the C++ standard only requires an abort() when this
happens. Therefore some users, apparently including Nicola Bertoldi, do
not see the .what() message and only see an opaque "Aborted" message.
The solution is to link in a file like this:
#include <cstdlib>
#include <exception>
#include <iostream>
namespace {
void terminate_handler() {
try { throw; }
catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
}
catch(...) {
std::cerr << "A non-standard exception was thrown." << std::endl;
}
std::abort();
}
struct ForceCall {
ForceCall() { std::set_terminate(terminate_handler); }
};
const ForceCall kForceCall;
} // namespace
This overrides the default handler so that the message is always
printed. It might be preferable to still print the type if RTTI is
available.
Alternatively, main() could just be wrapped in a try/catch block; that
would work in most cases except static/global constructors and
destructors. There are 34 main() functions.
Should I link this into the main moses binary?
Kenneth
_______________________________________________
Moses-support mailing list
[email protected]
http://mailman.mit.edu/mailman/listinfo/moses-support