Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <kenlm@kheafield.com>2012-01-13 19:20:42 +0400
committerKenneth Heafield <kenlm@kheafield.com>2012-01-13 19:20:42 +0400
commit868255af03abe072afd920d2fca594bb97f798e6 (patch)
treed29699355238ba9e6cbe8c085eebce51519e791a /moses-chart-cmd
parentcbf1e1e2bb68977c54eb2a2c9b5098271dc1af74 (diff)
Surround mains in try-catch blocks.
Diffstat (limited to 'moses-chart-cmd')
-rw-r--r--moses-chart-cmd/src/Main.cpp141
1 files changed, 74 insertions, 67 deletions
diff --git a/moses-chart-cmd/src/Main.cpp b/moses-chart-cmd/src/Main.cpp
index 50f2eaddb..6899582a4 100644
--- a/moses-chart-cmd/src/Main.cpp
+++ b/moses-chart-cmd/src/Main.cpp
@@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
//#include <vld.h>
#endif
+#include <exception>
#include <fstream>
#include "Main.h"
#include "FactorCollection.h"
@@ -202,81 +203,87 @@ static void ShowWeights()
int main(int argc, char* argv[])
{
- IFVERBOSE(1) {
- TRACE_ERR("command: ");
- for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" ");
- TRACE_ERR(endl);
- }
-
- IOWrapper::FixPrecision(cout);
- IOWrapper::FixPrecision(cerr);
-
- // load data structures
- Parameter parameter;
- if (!parameter.LoadParam(argc, argv)) {
- return EXIT_FAILURE;
- }
-
- const StaticData &staticData = StaticData::Instance();
- if (!StaticData::LoadDataStatic(&parameter))
- return EXIT_FAILURE;
-
- if (parameter.isParamSpecified("show-weights")) {
- ShowWeights();
- exit(0);
- }
-
- CHECK(staticData.GetSearchAlgorithm() == ChartDecoding);
-
- // set up read/writing class
- IOWrapper *ioWrapper = GetIODevice(staticData);
-
- // check on weights
- vector<float> weights = staticData.GetAllWeights();
- IFVERBOSE(2) {
- TRACE_ERR("The score component vector looks like this:\n" << staticData.GetScoreIndexManager());
- TRACE_ERR("The global weight vector looks like this:");
- for (size_t j=0; j<weights.size(); j++) {
- TRACE_ERR(" " << weights[j]);
+ try {
+ IFVERBOSE(1) {
+ TRACE_ERR("command: ");
+ for(int i=0; i<argc; ++i) TRACE_ERR(argv[i]<<" ");
+ TRACE_ERR(endl);
}
- TRACE_ERR("\n");
- }
- // every score must have a weight! check that here:
- if(weights.size() != staticData.GetScoreIndexManager().GetTotalNumberOfScores()) {
- TRACE_ERR("ERROR: " << staticData.GetScoreIndexManager().GetTotalNumberOfScores() << " score components, but " << weights.size() << " weights defined" << std::endl);
- return EXIT_FAILURE;
- }
-
- if (ioWrapper == NULL)
- return EXIT_FAILURE;
-
+
+ IOWrapper::FixPrecision(cout);
+ IOWrapper::FixPrecision(cerr);
+
+ // load data structures
+ Parameter parameter;
+ if (!parameter.LoadParam(argc, argv)) {
+ return EXIT_FAILURE;
+ }
+
+ const StaticData &staticData = StaticData::Instance();
+ if (!StaticData::LoadDataStatic(&parameter))
+ return EXIT_FAILURE;
+
+ if (parameter.isParamSpecified("show-weights")) {
+ ShowWeights();
+ exit(0);
+ }
+
+ CHECK(staticData.GetSearchAlgorithm() == ChartDecoding);
+
+ // set up read/writing class
+ IOWrapper *ioWrapper = GetIODevice(staticData);
+
+ // check on weights
+ vector<float> weights = staticData.GetAllWeights();
+ IFVERBOSE(2) {
+ TRACE_ERR("The score component vector looks like this:\n" << staticData.GetScoreIndexManager());
+ TRACE_ERR("The global weight vector looks like this:");
+ for (size_t j=0; j<weights.size(); j++) {
+ TRACE_ERR(" " << weights[j]);
+ }
+ TRACE_ERR("\n");
+ }
+ // every score must have a weight! check that here:
+ if(weights.size() != staticData.GetScoreIndexManager().GetTotalNumberOfScores()) {
+ TRACE_ERR("ERROR: " << staticData.GetScoreIndexManager().GetTotalNumberOfScores() << " score components, but " << weights.size() << " weights defined" << std::endl);
+ return EXIT_FAILURE;
+ }
+
+ if (ioWrapper == NULL)
+ return EXIT_FAILURE;
+
#ifdef WITH_THREADS
- ThreadPool pool(staticData.ThreadCount());
+ ThreadPool pool(staticData.ThreadCount());
#endif
-
- // read each sentence & decode
- InputType *source=0;
- while(ReadInput(*ioWrapper,staticData.GetInputType(),source)) {
- IFVERBOSE(1)
- ResetUserTime();
- TranslationTask *task = new TranslationTask(source, *ioWrapper);
- source = NULL; // task will delete source
+
+ // read each sentence & decode
+ InputType *source=0;
+ while(ReadInput(*ioWrapper,staticData.GetInputType(),source)) {
+ IFVERBOSE(1)
+ ResetUserTime();
+ TranslationTask *task = new TranslationTask(source, *ioWrapper);
+ source = NULL; // task will delete source
#ifdef WITH_THREADS
- pool.Submit(task); // pool will delete task
+ pool.Submit(task); // pool will delete task
#else
- task->Run();
- delete task;
+ task->Run();
+ delete task;
#endif
- }
-
+ }
+
#ifdef WITH_THREADS
- pool.Stop(true); // flush remaining jobs
+ pool.Stop(true); // flush remaining jobs
#endif
-
- delete ioWrapper;
-
- IFVERBOSE(1)
- PrintUserTime("End.");
+
+ delete ioWrapper;
+
+ IFVERBOSE(1)
+ PrintUserTime("End.");
+
+ } catch (const std::exception &e) {
+ std::cerr << "Exception: " << e.what() << std::endl;
+ return EXIT_FAILURE;
+ }
#ifdef HACK_EXIT
//This avoids that detructors are called (it can take a long time)