You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/05/17 00:16:06 UTC

[3/6] incubator-joshua git commit: System.exit() removed and replaced with RuntimeException(...)

System.exit() removed and replaced with RuntimeException(...)

Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/9848541f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/9848541f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/9848541f

Branch: refs/heads/JOSHUA-264
Commit: 9848541f6cf52e7d316d1bacc565004c1bbc3128
Parents: 7c8e856
Author: Thamme Gowda <tg...@gmail.com>
Authored: Mon May 16 14:33:29 2016 -0700
Committer: Thamme Gowda <tg...@gmail.com>
Committed: Mon May 16 14:33:29 2016 -0700

----------------------------------------------------------------------
 .../org/apache/joshua/adagrad/AdaGradCore.java  | 225 ++++++-------------
 .../org/apache/joshua/decoder/ArgsParser.java   |   5 +-
 .../java/org/apache/joshua/decoder/BLEU.java    |   6 +-
 .../java/org/apache/joshua/decoder/Decoder.java | 170 +++++++-------
 .../joshua/decoder/JoshuaConfiguration.java     | 109 +++++----
 .../org/apache/joshua/decoder/Translation.java  |   3 +-
 .../apache/joshua/decoder/ff/TargetBigram.java  |  50 ++---
 .../decoder/ff/fragmentlm/FragmentLMFF.java     |   5 +-
 .../joshua/decoder/ff/fragmentlm/Tree.java      |   9 +-
 .../org/apache/joshua/decoder/ff/lm/KenLM.java  |   6 +-
 .../joshua/decoder/ff/lm/LanguageModelFF.java   |   9 +-
 .../ff/lm/StateMinimizingLanguageModel.java     |   6 +-
 .../ff/lm/berkeley_lm/LMGrammarBerkeley.java    |   3 +-
 .../joshua/decoder/ff/phrase/Distortion.java    |   6 +-
 .../joshua/decoder/hypergraph/HGNode.java       |   4 +-
 .../joshua/decoder/phrase/PhraseTable.java      |   6 +-
 .../joshua/decoder/segment_file/Sentence.java   |   3 +-
 .../java/org/apache/joshua/metrics/BLEU.java    |  11 +-
 .../apache/joshua/metrics/EvaluationMetric.java |   5 +-
 .../apache/joshua/metrics/GradeLevelBLEU.java   |  10 +-
 .../java/org/apache/joshua/metrics/METEOR.java  |  37 ++-
 .../joshua/metrics/MinimumChangeBLEU.java       |   7 +-
 .../java/org/apache/joshua/metrics/Precis.java  |   7 +-
 .../joshua/metrics/PrecisMinusSourceBLEU.java   |   6 +-
 .../java/org/apache/joshua/metrics/TER.java     |  60 ++---
 .../org/apache/joshua/metrics/TERMinusBLEU.java |   6 +-
 .../org/apache/joshua/metrics/TercomRunner.java |  11 +-
 .../org/apache/joshua/metrics/ZeroOneLoss.java  |   3 +-
 .../java/org/apache/joshua/mira/MIRACore.java   | 211 ++++++-----------
 .../org/apache/joshua/pro/ClassifierMegaM.java  |  13 +-
 .../org/apache/joshua/pro/ClassifierSVM.java    |  14 +-
 .../java/org/apache/joshua/pro/Optimizer.java   |  13 +-
 .../java/org/apache/joshua/pro/PROCore.java     | 189 +++++-----------
 .../org/apache/joshua/server/TcpServer.java     |   4 +-
 .../org/apache/joshua/tools/GrammarPacker.java  |   9 +-
 .../org/apache/joshua/util/FileUtility.java     |  13 +-
 .../java/org/apache/joshua/util/JoshuaEval.java |  65 ++----
 .../org/apache/joshua/util/SocketUtility.java   |  11 +-
 .../util/encoding/EncoderConfiguration.java     |   6 +-
 .../util/encoding/FeatureTypeAnalyzer.java      |   3 +-
 .../joshua/zmert/IntermediateOptimizer.java     |  14 +-
 .../java/org/apache/joshua/zmert/MertCore.java  | 193 +++++-----------
 42 files changed, 551 insertions(+), 995 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/adagrad/AdaGradCore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/adagrad/AdaGradCore.java b/src/main/java/org/apache/joshua/adagrad/AdaGradCore.java
index 5e4abbc..9601a74 100755
--- a/src/main/java/org/apache/joshua/adagrad/AdaGradCore.java
+++ b/src/main/java/org/apache/joshua/adagrad/AdaGradCore.java
@@ -329,12 +329,8 @@ public class AdaGradCore {
       }
 
       inFile_names.close();
-    } catch (FileNotFoundException e) {
-      System.err.println("FileNotFoundException in AdaGradCore.initialize(int): " + e.getMessage());
-      System.exit(99901);
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.initialize(int): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
     // the parameter file contains one line per parameter
@@ -392,12 +388,8 @@ public class AdaGradCore {
           inFile_comm.close();
         }
       }
-    } catch (FileNotFoundException e) {
-      System.err.println("FileNotFoundException in AdaGradCore.initialize(int): " + e.getMessage());
-      System.exit(99901);
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.initialize(int): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
     // set static data members for the EvaluationMetric class
@@ -1221,13 +1213,8 @@ public class AdaGradCore {
         println("Number of features observed so far: " + numParams);
         println("", 1);
 
-      } catch (FileNotFoundException e) {
-        System.err.println("FileNotFoundException in AdaGradCore.run_single_iteration(6): "
-            + e.getMessage());
-        System.exit(99901);
       } catch (IOException e) {
-        System.err.println("IOException in AdaGradCore.run_single_iteration(6): " + e.getMessage());
-        System.exit(99902);
+        throw new RuntimeException(e);
       }
 
       // n-best list converges
@@ -1501,17 +1488,11 @@ public class AdaGradCore {
 
         int decStatus = p.waitFor();
         if (decStatus != validDecoderExitValue) {
-          println("Call to decoder returned " + decStatus + "; was expecting "
+          throw new RuntimeException("Call to decoder returned " + decStatus + "; was expecting "
               + validDecoderExitValue + ".");
-          System.exit(30);
         }
-      } catch (IOException e) {
-        System.err.println("IOException in AdaGradCore.run_decoder(int): " + e.getMessage());
-        System.exit(99902);
-      } catch (InterruptedException e) {
-        System.err.println("InterruptedException in AdaGradCore.run_decoder(int): "
-            + e.getMessage());
-        System.exit(99903);
+      } catch (IOException | InterruptedException e) {
+        throw new RuntimeException(e);
       }
 
       retSA[0] = decoderOutFileName;
@@ -1609,13 +1590,8 @@ public class AdaGradCore {
         gzipFile(featsFileName);
       }
 
-    } catch (FileNotFoundException e) {
-      System.err.println("FileNotFoundException in AdaGradCore.produceTempFiles(int): "
-          + e.getMessage());
-      System.exit(99901);
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.produceTempFiles(int): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
   }
@@ -1663,9 +1639,7 @@ public class AdaGradCore {
       inFile.close();
       outFile.close();
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.createConfigFile(double[],String,String): "
-          + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
   }
 
@@ -1675,9 +1649,7 @@ public class AdaGradCore {
     try {
       inFile_init = new Scanner(new FileReader(paramsFileName));
     } catch (FileNotFoundException e) {
-      System.err.println("FileNotFoundException in AdaGradCore.processParamFile(): "
-          + e.getMessage());
-      System.exit(99901);
+      throw new RuntimeException(e);
     }
 
     String dummy = "";
@@ -1700,8 +1672,7 @@ public class AdaGradCore {
       } else if (dummy.equals("Fix")) {
         isOptimizable[c] = false;
       } else {
-        println("Unknown isOptimizable string " + dummy + " (must be either Opt or Fix)");
-        System.exit(21);
+        throw new RuntimeException("Unknown isOptimizable string " + dummy + " (must be either Opt or Fix)");
       }
 
       if (!isOptimizable[c]) { // skip next two values
@@ -1716,25 +1687,22 @@ public class AdaGradCore {
         // set minRandValue[c] and maxRandValue[c] (range for random values)
         dummy = inFile_init.next();
         if (dummy.equals("-Inf") || dummy.equals("+Inf")) {
-          println("minRandValue[" + c + "] cannot be -Inf or +Inf!");
-          System.exit(21);
+          throw new RuntimeException("minRandValue[" + c + "] cannot be -Inf or +Inf!");
         } else {
           minRandValue[c] = Double.parseDouble(dummy);
         }
 
         dummy = inFile_init.next();
         if (dummy.equals("-Inf") || dummy.equals("+Inf")) {
-          println("maxRandValue[" + c + "] cannot be -Inf or +Inf!");
-          System.exit(21);
+          throw new RuntimeException("maxRandValue[" + c + "] cannot be -Inf or +Inf!");
         } else {
           maxRandValue[c] = Double.parseDouble(dummy);
         }
 
         // check for illogical values
         if (minRandValue[c] > maxRandValue[c]) {
-          println("minRandValue[" + c + "]=" + minRandValue[c] + " > " + maxRandValue[c]
+          throw new RuntimeException("minRandValue[" + c + "]=" + minRandValue[c] + " > " + maxRandValue[c]
               + "=maxRandValue[" + c + "]!");
-          System.exit(21);
         }
 
         // check for odd values
@@ -1785,40 +1753,34 @@ public class AdaGradCore {
       normalizationOptions[2] = Vocabulary.id(pName);
 
       if (normalizationOptions[1] <= 0) {
-        println("Value for the absval normalization method must be positive.");
-        System.exit(21);
+        throw new RuntimeException("Value for the absval normalization method must be positive.");
       }
       if (normalizationOptions[2] == 0) {
-        println("Unrecognized feature name " + normalizationOptions[2]
-            + " for absval normalization method.", 1);
-        System.exit(21);
+        throw new RuntimeException("Unrecognized feature name " + normalizationOptions[2]
+            + " for absval normalization method.");
       }
     } else if (dummyA[0].equals("maxabsval")) {
       normalizationOptions[0] = 2;
       normalizationOptions[1] = Double.parseDouble(dummyA[1]);
       if (normalizationOptions[1] <= 0) {
-        println("Value for the maxabsval normalization method must be positive.");
-        System.exit(21);
+        throw new RuntimeException("Value for the maxabsval normalization method must be positive.");
       }
     } else if (dummyA[0].equals("minabsval")) {
       normalizationOptions[0] = 3;
       normalizationOptions[1] = Double.parseDouble(dummyA[1]);
       if (normalizationOptions[1] <= 0) {
-        println("Value for the minabsval normalization method must be positive.");
-        System.exit(21);
+        throw new RuntimeException("Value for the minabsval normalization method must be positive.");
       }
     } else if (dummyA[0].equals("LNorm")) {
       normalizationOptions[0] = 4;
       normalizationOptions[1] = Double.parseDouble(dummyA[1]);
       normalizationOptions[2] = Double.parseDouble(dummyA[2]);
       if (normalizationOptions[1] <= 0 || normalizationOptions[2] <= 0) {
-        println("Both values for the LNorm normalization method must be positive.");
-        System.exit(21);
+        throw new RuntimeException("Both values for the LNorm normalization method must be positive.");
       }
     } else {
-      println("Unrecognized normalization method " + dummyA[0] + "; "
+      throw new RuntimeException("Unrecognized normalization method " + dummyA[0] + "; "
           + "must be one of none, absval, maxabsval, and LNorm.");
-      System.exit(21);
     } // if (dummyA[0])
 
     inFile_init.close();
@@ -1930,13 +1892,8 @@ public class AdaGradCore {
 
         }
 
-      } catch (FileNotFoundException e) {
-        System.err.println("FileNotFoundException in AdaGradCore.processDocInfo(): "
-            + e.getMessage());
-        System.exit(99901);
       } catch (IOException e) {
-        System.err.println("IOException in AdaGradCore.processDocInfo(): " + e.getMessage());
-        System.exit(99902);
+        throw new RuntimeException(e);
       }
     }
 
@@ -2037,8 +1994,7 @@ public class AdaGradCore {
         outFile_lambdas.close();
 
       } catch (IOException e) {
-        System.err.println("IOException in AdaGradCore.finish(): " + e.getMessage());
-        System.exit(99902);
+        throw new RuntimeException(e);
       }
     }
 
@@ -2119,9 +2075,8 @@ public class AdaGradCore {
               argsVector.add(paramA[opt]);
             }
           } else {
-            println("Malformed line in config file:");
-            println(origLine);
-            System.exit(70);
+            String msg = "Malformed line in config file:" + origLine;
+            throw new RuntimeException(msg);
           }
 
         }
@@ -2130,13 +2085,9 @@ public class AdaGradCore {
       inFile.close();
     } catch (FileNotFoundException e) {
       println("AdaGrad configuration file " + fileName + " was not found!");
-      System.err.println("FileNotFoundException in AdaGradCore.cfgFileToArgsArray(String): "
-          + e.getMessage());
-      System.exit(99901);
+      throw new RuntimeException(e);
     } catch (IOException e) {
-      System.err
-          .println("IOException in AdaGradCore.cfgFileToArgsArray(String): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
     String[] argsArray = new String[argsVector.size()];
@@ -2214,14 +2165,12 @@ public class AdaGradCore {
       } else if (option.equals("-rps")) {
         refsPerSen = Integer.parseInt(args[i + 1]);
         if (refsPerSen < 1) {
-          println("refsPerSen must be positive.");
-          System.exit(10);
+          throw new RuntimeException("refsPerSen must be positive.");
         }
       } else if (option.equals("-txtNrm")) {
         textNormMethod = Integer.parseInt(args[i + 1]);
         if (textNormMethod < 0 || textNormMethod > 4) {
-          println("textNormMethod should be between 0 and 4");
-          System.exit(10);
+          throw new RuntimeException("textNormMethod should be between 0 and 4");
         }
       } else if (option.equals("-p")) {
         paramsFileName = args[i + 1];
@@ -2241,8 +2190,7 @@ public class AdaGradCore {
           }
           i += optionCount;
         } else {
-          println("Unknown metric name " + metricName + ".");
-          System.exit(10);
+          throw new RuntimeException("Unknown metric name " + metricName + ".");
         }
       } else if (option.equals("-docSet")) {
         String method = args[i + 1];
@@ -2287,32 +2235,27 @@ public class AdaGradCore {
           docSubsetInfo[6] = Integer.parseInt(a2);
           i += 3;
         } else {
-          println("Unknown docSet method " + method + ".");
-          System.exit(10);
+          throw new RuntimeException("Unknown docSet method " + method + ".");
         }
       } else if (option.equals("-maxIt")) {
         maxMERTIterations = Integer.parseInt(args[i + 1]);
         if (maxMERTIterations < 1) {
-          println("maxIt must be positive.");
-          System.exit(10);
+          throw new RuntimeException("maxIt must be positive.");
         }
       } else if (option.equals("-minIt")) {
         minMERTIterations = Integer.parseInt(args[i + 1]);
         if (minMERTIterations < 1) {
-          println("minIt must be positive.");
-          System.exit(10);
+          throw new RuntimeException("minIt must be positive.");
         }
       } else if (option.equals("-prevIt")) {
         prevMERTIterations = Integer.parseInt(args[i + 1]);
         if (prevMERTIterations < 0) {
-          println("prevIt must be non-negative.");
-          System.exit(10);
+          throw new RuntimeException("prevIt must be non-negative.");
         }
       } else if (option.equals("-stopIt")) {
         stopMinIts = Integer.parseInt(args[i + 1]);
         if (stopMinIts < 1) {
-          println("stopIts must be positive.");
-          System.exit(10);
+          throw new RuntimeException("stopIts must be positive.");
         }
       } else if (option.equals("-stopSig")) {
         stopSigValue = Double.parseDouble(args[i + 1]);
@@ -2323,20 +2266,17 @@ public class AdaGradCore {
       else if (option.equals("-thrCnt")) {
         numOptThreads = Integer.parseInt(args[i + 1]);
         if (numOptThreads < 1) {
-          println("threadCount must be positive.");
-          System.exit(10);
+          throw new RuntimeException("threadCount must be positive.");
         }
       } else if (option.equals("-save")) {
         saveInterFiles = Integer.parseInt(args[i + 1]);
         if (saveInterFiles < 0 || saveInterFiles > 3) {
-          println("save should be between 0 and 3");
-          System.exit(10);
+          throw new RuntimeException("save should be between 0 and 3");
         }
       } else if (option.equals("-compress")) {
         compressFiles = Integer.parseInt(args[i + 1]);
         if (compressFiles < 0 || compressFiles > 1) {
-          println("compressFiles should be either 0 or 1");
-          System.exit(10);
+          throw new RuntimeException("compressFiles should be either 0 or 1");
         }
       } else if (option.equals("-opi")) {
         int opi = Integer.parseInt(args[i + 1]);
@@ -2345,8 +2285,7 @@ public class AdaGradCore {
         } else if (opi == 0) {
           oneModificationPerIteration = false;
         } else {
-          println("oncePerIt must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("oncePerIt must be either 0 or 1.");
         }
       } else if (option.equals("-rand")) {
         int rand = Integer.parseInt(args[i + 1]);
@@ -2355,8 +2294,7 @@ public class AdaGradCore {
         } else if (rand == 0) {
           randInit = false;
         } else {
-          println("randInit must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("randInit must be either 0 or 1.");
         }
       } else if (option.equals("-seed")) {
         if (args[i + 1].equals("time")) {
@@ -2378,8 +2316,7 @@ public class AdaGradCore {
         else if (shuffle == 0)
           needShuffle = false;
         else {
-          println("-needShuffle must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("-needShuffle must be either 0 or 1.");
         }
       }
       // average weights after each epoch or not
@@ -2390,8 +2327,7 @@ public class AdaGradCore {
         else if (avg == 0)
           needAvg = false;
         else {
-          println("-needAvg must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("-needAvg must be either 0 or 1.");
         }
       }
       // return the best weight during tuning or not
@@ -2402,8 +2338,7 @@ public class AdaGradCore {
         else if (retBest == 0)
           returnBest = false;
         else {
-          println("-returnBest must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("-returnBest must be either 0 or 1.");
         }
       }
       // mini-batch size
@@ -2446,8 +2381,7 @@ public class AdaGradCore {
       else if (option.equals("-scoreRatio")) {
         scoreRatio = Double.parseDouble(args[i + 1]);
         if (scoreRatio <= 0) {
-          println("-scoreRatio must be positive");
-          System.exit(10);
+          throw new RuntimeException("-scoreRatio must be positive");
         }
       } else if (option.equals("-needScaling")) {
         int scale = Integer.parseInt(args[i + 1]);
@@ -2456,8 +2390,7 @@ public class AdaGradCore {
         else if (scale == 0)
           needScale = false;
         else {
-          println("-needScaling must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("-needScaling must be either 0 or 1.");
         }
       } else if (option.equals("-usePseudoCorpus")) {
         int use = Integer.parseInt(args[i + 1]);
@@ -2466,8 +2399,7 @@ public class AdaGradCore {
         else if (use == 0)
           usePseudoBleu = false;
         else {
-          println("-usePseudoCorpus must be either 0 or 1.");
-          System.exit(10);
+          throw new RuntimeException("-usePseudoCorpus must be either 0 or 1.");
         }
       } else if (option.equals("-corpusDecay")) {
         R = Double.parseDouble(args[i + 1]);
@@ -2479,8 +2411,7 @@ public class AdaGradCore {
       } else if (option.equals("-passIt")) {
         int val = Integer.parseInt(args[i + 1]);
         if (val < 0 || val > 1) {
-          println("passIterationToDecoder should be either 0 or 1");
-          System.exit(10);
+          throw new RuntimeException("passIterationToDecoder should be either 0 or 1");
         }
         passIterationToDecoder = (val == 1) ? true : false;
       } else if (option.equals("-decOut")) {
@@ -2492,35 +2423,30 @@ public class AdaGradCore {
       } else if (option.equals("-N")) {
         sizeOfNBest = Integer.parseInt(args[i + 1]);
         if (sizeOfNBest < 1) {
-          println("N must be positive.");
-          System.exit(10);
+          throw new RuntimeException("N must be positive.");
         }
       }
       // Output specs
       else if (option.equals("-v")) {
         verbosity = Integer.parseInt(args[i + 1]);
         if (verbosity < 0 || verbosity > 4) {
-          println("verbosity should be between 0 and 4");
-          System.exit(10);
+          throw new RuntimeException("verbosity should be between 0 and 4");
         }
       } else if (option.equals("-decV")) {
         decVerbosity = Integer.parseInt(args[i + 1]);
         if (decVerbosity < 0 || decVerbosity > 1) {
-          println("decVerbosity should be either 0 or 1");
-          System.exit(10);
+          throw new RuntimeException("decVerbosity should be either 0 or 1");
         }
       } else if (option.equals("-fake")) {
         fakeFileNameTemplate = args[i + 1];
         int QM_i = fakeFileNameTemplate.indexOf("?");
         if (QM_i <= 0) {
-          println("fakeFileNameTemplate must contain '?' to indicate position of iteration number");
-          System.exit(10);
+          throw new RuntimeException("fakeFileNameTemplate must contain '?' to indicate position of iteration number");
         }
         fakeFileNamePrefix = fakeFileNameTemplate.substring(0, QM_i);
         fakeFileNameSuffix = fakeFileNameTemplate.substring(QM_i + 1);
       } else {
-        println("Unknown option " + option);
-        System.exit(10);
+        throw new RuntimeException("Unknown option " + option);
       }
 
       i += 2;
@@ -2592,10 +2518,11 @@ public class AdaGradCore {
     if (!canRunCommand && !canRunJoshua) { // can only run fake decoder
 
       if (!canRunFake) {
-        println("AdaGrad cannot decode; must provide one of: command file (for external decoder),");
-        println("                                           source file (for Joshua decoder),");
-        println("                                        or prefix for existing output files (for fake decoder).");
-        System.exit(12);
+        String msg = "AdaGrad cannot decode; must provide one of:"
+            + " command file (for external decoder),"
+            + " source file (for Joshua decoder),"
+            + " or prefix for existing output files (for fake decoder).";
+        throw new RuntimeException(msg);
       }
 
       int lastGoodIt = 0;
@@ -2608,9 +2535,8 @@ public class AdaGradCore {
       }
 
       if (lastGoodIt == 0) {
-        println("Fake decoder cannot find first output file "
+        throw new RuntimeException("Fake decoder cannot find first output file "
             + (fakeFileNamePrefix + 1 + fakeFileNameSuffix));
-        System.exit(13);
       } else if (lastGoodIt < maxMERTIterations) {
         if (firstTime)
           println("Warning: can only run fake decoder; existing output files "
@@ -2702,8 +2628,7 @@ public class AdaGradCore {
 
   private void checkFile(String fileName) {
     if (!fileExists(fileName)) {
-      println("The file " + fileName + " was not found!");
-      System.exit(40);
+      throw new RuntimeException("The file " + fileName + " was not found!");
     }
   }
 
@@ -2738,8 +2663,7 @@ public class AdaGradCore {
       deleteFile(inputFileName);
 
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.gzipFile(String,String): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2771,8 +2695,7 @@ public class AdaGradCore {
       deleteFile(gzippedFileName);
 
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.gunzipFile(String,String): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
   }
 
@@ -2788,8 +2711,8 @@ public class AdaGradCore {
       if (!checker.exists()) {
         checker = new File(prefix + ".1");
         if (!checker.exists()) {
-          println("Can't find reference files.");
-          System.exit(50);
+          String msg = "Can't find reference files.";
+          throw new RuntimeException(msg);
         } else {
           prefix = prefix + ".";
         }
@@ -2818,8 +2741,8 @@ public class AdaGradCore {
 
         for (int r = 0; r < numFiles; ++r) {
           if (countLines(prefix + nextIndex) != lineCount) {
-            println("Line count mismatch in " + (prefix + nextIndex) + ".");
-            System.exit(60);
+            String msg = "Line count mismatch in " + (prefix + nextIndex) + ".";
+            throw new RuntimeException(msg);
           }
           InputStream inStream = new FileInputStream(new File(prefix + nextIndex));
           inFile[r] = new BufferedReader(new InputStreamReader(inStream, "utf8"));
@@ -2840,15 +2763,8 @@ public class AdaGradCore {
         for (int r = 0; r < numFiles; ++r) {
           inFile[r].close();
         }
-      } catch (FileNotFoundException e) {
-        System.err
-            .println("FileNotFoundException in AdaGradCore.createUnifiedRefFile(String,int): "
-                + e.getMessage());
-        System.exit(99901);
       } catch (IOException e) {
-        System.err.println("IOException in AdaGradCore.createUnifiedRefFile(String,int): "
-            + e.getMessage());
-        System.exit(99902);
+        throw new RuntimeException(e);
       }
 
       return outFileName;
@@ -3001,8 +2917,7 @@ public class AdaGradCore {
 
       inFile.close();
     } catch (IOException e) {
-      System.err.println("IOException in AdaGradCore.countLines(String): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
     return count;
@@ -3023,9 +2938,7 @@ public class AdaGradCore {
 
       inFile.close();
     } catch (IOException e) {
-      System.err
-          .println("IOException in AdaGradCore.countNonEmptyLines(String): " + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException(e);
     }
 
     return count;
@@ -3157,8 +3070,8 @@ public class AdaGradCore {
         randVal = randVal * sigma; // number in [-sigma,sigma]
         randVal = randVal * origLambda[c]; // number in [-sigma*orig[c],sigma*orig[c]]
         randVal = randVal + origLambda[c]; // number in
-                                           // [orig[c]-sigma*orig[c],orig[c]+sigma*orig[c]]
-                                           // = [orig[c]*(1-sigma),orig[c]*(1+sigma)]
+        // [orig[c]-sigma*orig[c],orig[c]+sigma*orig[c]]
+        // = [orig[c]*(1-sigma),orig[c]*(1+sigma)]
         retLambda[c] = randVal;
       } else {
         retLambda[c] = origLambda[c];

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ArgsParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ArgsParser.java b/src/main/java/org/apache/joshua/decoder/ArgsParser.java
index 016b0c5..fea20fc 100644
--- a/src/main/java/org/apache/joshua/decoder/ArgsParser.java
+++ b/src/main/java/org/apache/joshua/decoder/ArgsParser.java
@@ -71,7 +71,7 @@ public class ArgsParser {
               System.out.println(line);
             }
           } catch (IOException e) {
-            System.err.println("FATAL: missing license file!");
+            throw new RuntimeException("FATAL: missing license file!", e);
           }
           System.exit(0);
         }
@@ -86,8 +86,7 @@ public class ArgsParser {
             Decoder.LOG(1, "Parameters read from configuration file:");
             joshuaConfiguration.readConfigFile(getConfigFile());
           } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            throw new RuntimeException(e);
           }
 
           break;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/BLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/BLEU.java b/src/main/java/org/apache/joshua/decoder/BLEU.java
index 43082a8..a531611 100644
--- a/src/main/java/org/apache/joshua/decoder/BLEU.java
+++ b/src/main/java/org/apache/joshua/decoder/BLEU.java
@@ -213,8 +213,7 @@ public class BLEU {
   // sentence-bleu: BLEU= bp * prec; where prec = exp (sum 1/4 * log(prec[order]))
   public static float computeBleu(int hypLen, float refLen, int[] numNgramMatch, int bleuOrder) {
     if (hypLen <= 0 || refLen <= 0) {
-      System.out.println("error: ref or hyp is zero len");
-      System.exit(1);
+      throw new RuntimeException("error: ref or hyp is zero len");
     }
     float res = 0;
     float wt = 1.0f / bleuOrder;
@@ -376,10 +375,9 @@ public class BLEU {
           try {
             ngramState = (NgramDPState) edge.getTailNodes().get(tailIndex).getDPState(0);
           } catch (ClassCastException e) {
-            System.err.println(String.format(
+            throw new RuntimeException(String.format(
                 "* FATAL: first state needs to be NgramDPState (found %s)", edge.getTailNodes()
                     .get(tailIndex).getDPState(0).getClass()));
-            System.exit(1);
           }
           
           // Compute ngrams overlapping with left context of tail node

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/Decoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/Decoder.java b/src/main/java/org/apache/joshua/decoder/Decoder.java
index 43f845c..1aac0b0 100644
--- a/src/main/java/org/apache/joshua/decoder/Decoder.java
+++ b/src/main/java/org/apache/joshua/decoder/Decoder.java
@@ -20,7 +20,7 @@ package org.apache.joshua.decoder;
 
 import static org.apache.joshua.decoder.ff.FeatureVector.DENSE_FEATURE_NAMES;
 
-import java.io.BufferedWriter;	
+import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -62,7 +62,7 @@ import org.apache.joshua.util.io.LineReader;
 
 /**
  * This class handles decoder initialization and the complication introduced by multithreading.
- * 
+ *
  * After initialization, the main entry point to the Decoder object is
  * decodeAll(TranslationRequest), which returns a set of Translation objects wrapped in an iterable
  * Translations object. It is important that we support multithreading both (a) across the sentences
@@ -74,12 +74,12 @@ import org.apache.joshua.util.io.LineReader;
  * parallelization by separating out reading the input stream from processing the translated sentences,
  * but also ensures that round-robin parallelization occurs, since RequestParallelizer uses the
  * thread pool before translating each request.
- * 
+ *
  * A decoding thread is handled by DecoderThread and launched from DecoderThreadRunner. The purpose
  * of the runner is to record where to place the translated sentence when it is done (i.e., which
  * Translations object). Translations itself is an iterator whose next() call blocks until the next
  * translation is available.
- * 
+ *
  * @author Matt Post <po...@cs.jhu.edu>
  * @author Zhifei Li, <zh...@gmail.com>
  * @author wren ng thornton <wr...@users.sourceforge.net>
@@ -116,7 +116,7 @@ public class Decoder {
 
   /**
    * Constructor method that creates a new decoder using the specified configuration file.
-   * 
+   *
    * @param configFile Name of configuration file.
    */
   public Decoder(JoshuaConfiguration joshuaConfiguration, String configFile) {
@@ -126,7 +126,7 @@ public class Decoder {
 
   /**
    * Factory method that creates a new decoder using the specified configuration file.
-   * 
+   *
    * @param configFile Name of configuration file.
    */
   public static Decoder createDecoder(String configFile) {
@@ -168,9 +168,9 @@ public class Decoder {
    * DecoderThreadRunner to translate it. Each call to decodeAll(TranslationRequest) launches a
    * thread that will read the request's sentences, obtain a DecoderThread to translate them, and
    * then place the Translation in the appropriate place.
-   * 
+   *
    * @author Matt Post <po...@cs.jhu.edu>
-   * 
+   *
    */
   private class RequestParallelizer extends Thread {
     /* Source of sentences to translate. */
@@ -178,12 +178,12 @@ public class Decoder {
 
     /* Where to put translated sentences. */
     private final Translations response;
-    
+
     /* Sometimes we need to communicate with the client even when we didn't get a new sentence
      * (e.g., metadata)
      */
     private OutputStream out;
-    
+
     RequestParallelizer(TranslationRequestStream request, Translations response, OutputStream out) {
       this.request = request;
       this.response = response;
@@ -202,7 +202,7 @@ public class Decoder {
         Sentence sentence = null;
         try {
           sentence = request.next();
-          
+
         } catch (MetaDataException meta) {
           try {
             handleMetadata(meta);
@@ -212,7 +212,7 @@ public class Decoder {
 
           continue;
         }
-        
+
         if (sentence == null) {
           response.finish();
           break;
@@ -227,7 +227,7 @@ public class Decoder {
     /**
      * When metadata is found on the input, it needs to be processed. That is done here. Sometimes
      * this involves returning data to the client.
-     * 
+     *
      * @param meta
      * @throws IOException
      */
@@ -240,23 +240,23 @@ public class Decoder {
         } else {
           float old_weight = Decoder.weights.getWeight(tokens[1]);
           Decoder.weights.set(tokens[1], Float.parseFloat(tokens[2]));
-          System.err.println(String.format("@set_weight: %s %.3f -> %.3f", 
+          System.err.println(String.format("@set_weight: %s %.3f -> %.3f",
               tokens[1], old_weight,
               Decoder.weights.getWeight(tokens[1])));
         }
-        
+
         // TODO: return a JSON object with this weight or all weights
         out.write("".getBytes());
 
       } else if (meta.type().equals("get_weight")) {
         // TODO: add to JSON object, send back
-        
+
         String[] tokens = meta.tokens();
-        
+
         System.err.println(String.format("%s = %f", tokens[1], Decoder.weights.getWeight(tokens[1])));
 
         out.write("".getBytes());
-                
+
       } else if (meta.type().equals("add_rule")) {
         String tokens[] = meta.tokens(" \\|\\|\\| ");
 
@@ -271,21 +271,21 @@ public class Decoder {
         Decoder.this.customPhraseTable.addRule(rule);
         rule.estimateRuleCost(featureFunctions);
         Decoder.LOG(1, String.format("Added custom rule %s", formatRule(rule)));
-        
+
         String response = String.format("Added rule %s", formatRule(rule));
         out.write(response.getBytes());
 
       } else if (meta.type().equals("list_rules")) {
-        
+
         JSONMessage message = new JSONMessage();
-        
+
         // Walk the the grammar trie
         ArrayList<Trie> nodes = new ArrayList<Trie>();
         nodes.add(customPhraseTable.getTrieRoot());
-        
+
         while (nodes.size() > 0) {
           Trie trie = nodes.remove(0);
-          
+
           if (trie == null)
             continue;
 
@@ -298,9 +298,9 @@ public class Decoder {
           if (trie.getExtensions() != null)
             nodes.addAll(trie.getExtensions());
         }
-        
+
         out.write(message.toString().getBytes());
-        
+
       } else if (meta.type().equals("remove_rule")) {
         // Remove a rule from a custom grammar, if present
         String[] tokens = meta.tokenString().split(" \\|\\|\\| ");
@@ -325,7 +325,7 @@ public class Decoder {
           for (Rule rule: trie.getRuleCollection().getRules()) {
             String target = rule.getEnglishWords();
             target = target.substring(target.indexOf(' ') + 1);
-            
+
             if (tokens[1].equals(target)) {
               matched = rule;
               break;
@@ -335,14 +335,14 @@ public class Decoder {
           out.write(String.format("Removed rule %s", formatRule(matched)).getBytes());
           return;
         }
-        
+
         out.write(String.format("No such rule %s", meta.tokenString()).getBytes());
       }
     }
 
     /**
      * Strips the nonterminals from the lefthand side of the rule.
-     * 
+     *
      * @param rule
      * @return
      */
@@ -354,7 +354,7 @@ public class Decoder {
           ruleString += " " + Vocabulary.word(word);
         first = false;
       }
-      
+
       ruleString += " |||"; // space will get added with first English word
       first = true;
       for (int word: rule.getEnglish()) {
@@ -371,7 +371,7 @@ public class Decoder {
   /**
    * Retrieve a thread from the thread pool, blocking until one is available. The blocking occurs in
    * a fair fashion (i.e,. FIFO across requests).
-   * 
+   *
    * @return a thread that can be used for decoding.
    */
   public DecoderThread getThread() {
@@ -389,11 +389,11 @@ public class Decoder {
    * input Sentence, returning a Translation object when its done). This is done in a thread so as
    * not to tie up the RequestHandler that launched it, freeing it to go on to the next sentence in
    * the TranslationRequest, in turn permitting parallelization across the sentences of a request.
-   * 
+   *
    * When the decoder thread is finshed, the Translation object is placed in the correct place in
    * the corresponding Translations object that was returned to the caller of
    * Decoder.decodeAll(TranslationRequest).
-   * 
+   *
    * @author Matt Post <po...@cs.jhu.edu>
    */
   private class DecoderThreadRunner extends Thread {
@@ -424,11 +424,9 @@ public class Decoder {
          */
         threadPool.put(decoderThread);
       } catch (Exception e) {
-        System.err.println(String.format(
-            "Input %d: FATAL UNCAUGHT EXCEPTION: %s", sentence.id(), e.getMessage()));
-        e.printStackTrace();
-        System.exit(1);;
-//        translations.record(new Translation(sentence, null, featureFunctions, joshuaConfiguration));
+        throw new RuntimeException(String.format(
+            "Input %d: FATAL UNCAUGHT EXCEPTION: %s", sentence.id(), e.getMessage()), e);
+        //        translations.record(new Translation(sentence, null, featureFunctions, joshuaConfiguration));
       }
     }
   }
@@ -437,22 +435,22 @@ public class Decoder {
    * This function is the main entry point into the decoder. It translates all the sentences in a
    * (possibly boundless) set of input sentences. Each request launches its own thread to read the
    * sentences of the request.
-   * 
+   *
    * @param request
    * @return an iterable set of Translation objects
-   * @throws IOException 
+   * @throws IOException
    */
   public void decodeAll(TranslationRequestStream request, OutputStream out) throws IOException {
     Translations translations = new Translations(request);
 
     /* Start a thread to handle requests on the input stream */
     new RequestParallelizer(request, translations, out).start();
-    
+
     // Create the n-best output stream
     FileWriter nbest_out = null;
     if (joshuaConfiguration.n_best_file != null)
       nbest_out = new FileWriter(joshuaConfiguration.n_best_file);
-    
+
     for (;;) {
       Translation translation = translations.next();
       if (translation == null)
@@ -461,7 +459,7 @@ public class Decoder {
       if (joshuaConfiguration.input_type == INPUT_TYPE.json || joshuaConfiguration.server_type == SERVER_TYPE.HTTP) {
         JSONMessage message = JSONMessage.buildMessage(translation);
         out.write(message.toString().getBytes());
-        
+
       } else {
         /**
          * We need to munge the feature value outputs in order to be compatible with Moses tuners.
@@ -475,12 +473,12 @@ public class Decoder {
           // Write the complete formatted string to STDOUT
           if (joshuaConfiguration.n_best_file != null)
             nbest_out.write(text);
-          
+
           // Extract just the translation and output that to STDOUT
           text = text.substring(0,  text.indexOf('\n'));
           String[] fields = text.split(" \\|\\|\\| ");
           text = fields[1] + "\n";
-          
+
         } else {
           text = translation.toString();
         }
@@ -489,7 +487,7 @@ public class Decoder {
       }
       out.flush();
     }
-    
+
     if (joshuaConfiguration.n_best_file != null)
       nbest_out.close();
   }
@@ -497,7 +495,7 @@ public class Decoder {
 
   /**
    * We can also just decode a single sentence.
-   * 
+   *
    * @param sentence
    * @return The translated sentence
    */
@@ -534,7 +532,7 @@ public class Decoder {
     }
     resetGlobalState();
   }
-  
+
   public static void resetGlobalState() {
     // clear/reset static variables
     DENSE_FEATURE_NAMES.clear();
@@ -570,7 +568,7 @@ public class Decoder {
             if (newDiscriminativeModel != null && "discriminative".equals(fds[0])) {
               newSent.append(fds[0]).append(' ');
               newSent.append(newDiscriminativeModel).append(' ');// change the
-                                                                 // file name
+              // file name
               for (int i = 2; i < fds.length - 1; i++) {
                 newSent.append(fds[i]).append(' ');
               }
@@ -610,7 +608,7 @@ public class Decoder {
    * Moses requires the pattern .*_.* for sparse features, and prohibits underscores in dense features. 
    * This conforms to that pattern. We assume non-conforming dense features start with tm_ or lm_,
    * and the only sparse feature that needs converting is OOVPenalty.
-   * 
+   *
    * @param feature
    * @return the feature in Moses format
    */
@@ -619,13 +617,13 @@ public class Decoder {
       if (feature.startsWith("tm_") || feature.startsWith("lm_"))
         return feature.replace("_", "-");
     }
-    
+
     return feature;
   }
-  
+
   /**
    * Initialize all parts of the JoshuaDecoder.
-   * 
+   *
    * @param configFile File containing configuration options
    * @return An initialized decoder
    */
@@ -646,10 +644,10 @@ public class Decoder {
         for (int i = 0; i < tokens.length; i += 2) {
           String feature = tokens[i];
           float value = Float.parseFloat(tokens[i+1]);
-          
+
           if (joshuaConfiguration.moses)
             feature = demoses(feature);
-          
+
           joshuaConfiguration.weights.add(String.format("%s %s", feature, tokens[i+1]));
           Decoder.LOG(1, String.format("COMMAND LINE WEIGHT: %s -> %.3f", feature, value));
         }
@@ -661,21 +659,20 @@ public class Decoder {
 
         /* Sanity check for old-style unsupported feature invocations. */
         if (pair.length != 2) {
-          System.err.println("FATAL: Invalid feature weight line found in config file.");
-          System.err
-              .println(String.format("The line was '%s'", pairStr));
-          System.err
-              .println("You might be using an old version of the config file that is no longer supported");
-          System.err
-              .println("Check joshua-decoder.org or email joshua_support@googlegroups.com for help");
-          System.exit(17);
+          StringBuilder errMsg = new StringBuilder();
+          errMsg.append("FATAL: Invalid feature weight line found in config file.\n");
+          errMsg.append(String.format("The line was '%s'\n", pairStr));
+          errMsg.append("You might be using an old version of the config file that is no longer supported\n");
+          errMsg.append("Check joshua-decoder.org or email joshua_support@googlegroups.com for help\n");
+          errMsg.append("Code = " + 17);
+          throw new RuntimeException(errMsg.toString());
         }
 
         weights.set(pair[0], Float.parseFloat(pair[1]));
       }
 
       Decoder.LOG(1, String.format("Read %d weights (%d of them dense)", weights.size(),
-      DENSE_FEATURE_NAMES.size()));
+          DENSE_FEATURE_NAMES.size()));
 
       // Do this before loading the grammars and the LM.
       this.featureFunctions = new ArrayList<FeatureFunction>();
@@ -694,14 +691,14 @@ public class Decoder {
       if (joshuaConfiguration.show_weights_and_quit) {
         for (int i = 0; i < DENSE_FEATURE_NAMES.size(); i++) {
           String name = DENSE_FEATURE_NAMES.get(i);
-          if (joshuaConfiguration.moses) 
+          if (joshuaConfiguration.moses)
             System.out.println(String.format("%s= %.5f", mosesize(name), weights.getDense(i)));
           else
             System.out.println(String.format("%s %.5f", name, weights.getDense(i)));
         }
         System.exit(0);
       }
-      
+
       // Sort the TM grammars (needed to do cube pruning)
       if (joshuaConfiguration.amortized_sorting) {
         Decoder.LOG(1, "Grammar sorting happening lazily on-demand.");
@@ -732,7 +729,7 @@ public class Decoder {
 
   /**
    * Initializes translation grammars Retained for backward compatibility
-   * 
+   *
    * @param ownersSeen Records which PhraseModelFF's have been instantiated (one is needed for each
    *          owner)
    * @throws IOException
@@ -763,19 +760,19 @@ public class Decoder {
               packed_grammars.add(packed_grammar);
               grammar = packed_grammar;
             } catch (FileNotFoundException e) {
-              System.err.println(String.format("Couldn't load packed grammar from '%s'", path));
-              System.err.println("Perhaps it doesn't exist, or it may be an old packed file format.");
-              System.exit(2);
+              String msg = String.format("Couldn't load packed grammar from '%s'", path)
+                  + "Perhaps it doesn't exist, or it may be an old packed file format.";
+              throw new RuntimeException(e);
             }
           } else {
             // thrax, hiero, samt
             grammar = new MemoryBasedBatchGrammar(type, path, owner,
                 joshuaConfiguration.default_non_terminal, span_limit, joshuaConfiguration);
           }
-          
+
         } else {
 
-          int maxSourceLen = parsedArgs.containsKey("max-source-len") 
+          int maxSourceLen = parsedArgs.containsKey("max-source-len")
               ? Integer.parseInt(parsedArgs.get("max-source-len"))
               : -1;
 
@@ -831,11 +828,11 @@ public class Decoder {
         ownersSeen.add(owner);
       }
     }
-      
+
     Decoder.LOG(1, String.format("Memory used %.1f MB",
         ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000.0)));
   }
-  
+
   /**
    * Checks if multiple packedGrammars have the same vocabulary by comparing their vocabulary file checksums.
    */
@@ -849,7 +846,7 @@ public class Decoder {
         if (!checksum.equals(previous_checksum)) {
           throw new RuntimeException(
               "Trying to load multiple packed grammars with different vocabularies!" +
-              "Have you packed them jointly?");
+                  "Have you packed them jointly?");
         }
         previous_checksum = checksum;
       }
@@ -881,7 +878,7 @@ public class Decoder {
         String tokens[] = line.split("\\s+");
         String feature = tokens[0];
         Float value = Float.parseFloat(tokens[1]);
-        
+
         // Kludge for compatibility with Moses tuners
         if (joshuaConfiguration.moses) {
           feature = demoses(feature);
@@ -889,15 +886,9 @@ public class Decoder {
 
         weights.increment(feature, value);
       }
-    } catch (FileNotFoundException ioe) {
-      System.err.println("* FATAL: Can't find weights-file '" + fileName + "'");
-      System.exit(1);
     } catch (IOException ioe) {
-      System.err.println("* FATAL: Can't read weights-file '" + fileName + "'");
-      ioe.printStackTrace();
-      System.exit(1);
+      throw new RuntimeException(ioe);
     }
-    
     Decoder.LOG(1, String.format("Read %d weights from file '%s'", weights.size(), fileName));
   }
 
@@ -913,16 +904,16 @@ public class Decoder {
 
   /**
    * Feature functions are instantiated with a line of the form
-   * 
+   *
    * <pre>
    *   feature_function = FEATURE OPTIONS
    * </pre>
-   * 
+   *
    * Weights for features are listed separately.
-   * 
+   *
    * @param tmOwnersSeen
    * @throws IOException
-   * 
+   *
    */
   private void initializeFeatureFunctions() throws IOException {
 
@@ -942,14 +933,13 @@ public class Decoder {
         this.featureFunctions.add((FeatureFunction) constructor.newInstance(weights, fields, joshuaConfiguration));
       } catch (Exception e) {
         e.printStackTrace();
-        System.err.println("* FATAL: could not find a feature '" + featureName + "'");
-        System.exit(1);
+        throw new RuntimeException("* FATAL: could not find a feature '" + featureName + "'");
       }
     }
 
     for (FeatureFunction feature : featureFunctions) {
       Decoder.LOG(1, String.format("FEATURE: %s", feature.logString()));
-      
+
     }
 
     weights.registerDenseFeatures(featureFunctions);
@@ -958,7 +948,7 @@ public class Decoder {
   /**
    * Searches a list of predefined paths for classes, and returns the first one found. Meant for
    * instantiating feature functions.
-   * 
+   *
    * @param name
    * @return the class, found in one of the search paths
    * @throws ClassNotFoundException

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/JoshuaConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/JoshuaConfiguration.java b/src/main/java/org/apache/joshua/decoder/JoshuaConfiguration.java
index bf8cfb3..b4624cf 100644
--- a/src/main/java/org/apache/joshua/decoder/JoshuaConfiguration.java
+++ b/src/main/java/org/apache/joshua/decoder/JoshuaConfiguration.java
@@ -39,23 +39,23 @@ import org.apache.joshua.util.io.LineReader;
 
 /**
  * Configuration file for Joshua decoder.
- * 
+ *
  * When adding new features to Joshua, any new configurable parameters should be added to this
  * class.
- * 
+ *
  * @author Zhifei Li, <zh...@gmail.com>
  * @author Matt Post <po...@cs.jhu.edu>
  */
 public class JoshuaConfiguration {
-  
+
   // whether to construct a StructuredTranslation object for each request instead of 
   // printing to stdout. Used when the Decoder is used from Java directly.
   public Boolean use_structured_output = false;
-  
+
   // If set to true, Joshua will lowercase the input, creating an annotation that marks the
   // original case
   public boolean lowercase = false;
-  
+
   // If set to true, Joshua will recapitalize the output by projecting the case from aligned
   // source-side words
   public boolean project_case = false;
@@ -89,7 +89,7 @@ public class JoshuaConfiguration {
    * 
    * If this is empty, an unweighted default_non_terminal is used.
    */
-  
+
   public class OOVItem implements Comparable<OOVItem> {
     public String label;
     public float weight;
@@ -98,10 +98,10 @@ public class JoshuaConfiguration {
       label = l;
       weight = w;
     }
-    
+
     @Override
     public int compareTo(OOVItem other) {
-      if (weight > other.weight) 
+      if (weight > other.weight)
         return -1;
       else if (weight < other.weight)
         return 1;
@@ -114,12 +114,12 @@ public class JoshuaConfiguration {
    * Whether to segment OOVs into a lattice
    */
   public boolean segment_oovs = false;
-  
+
   /*
    * Enable lattice decoding.
    */
   public boolean lattice_decoding = false;
-  
+
   /*
    * If false, sorting of the complete grammar is done at load time. If true, grammar tries are not
    * sorted till they are first accessed. Amortized sorting means you get your first translation
@@ -154,12 +154,12 @@ public class JoshuaConfiguration {
 
   /* The number of hypotheses to output by default. */
   public int topN = 1;
-  
+
   /**
    * This string describes the format of each line of output from the decoder (i.e., the
    * translations). The string can include arbitrary text and also variables. The following
    * variables are available:
-   * 
+   *
    * <pre>
    * - %i the 0-indexed sentence number 
    * - %e the source string %s the translated sentence 
@@ -204,7 +204,7 @@ public class JoshuaConfiguration {
   /* Type of server. Not sure we need to keep the regular TCP one around. */
   public enum SERVER_TYPE { none, TCP, HTTP };
   public SERVER_TYPE server_type = SERVER_TYPE.TCP;
-  
+
   /* If set, Joshua will start a (multi-threaded, per "threads") TCP/IP server on this port. */
   public int server_port = 0;
 
@@ -240,10 +240,10 @@ public class JoshuaConfiguration {
   
   /* The search algorithm: currently either "cky" or "stack" */
   public String search_algorithm = "cky";
-  
+
   /* The distortion limit */
   public int reordering_limit = 8;
-  
+
   /* The number of target sides considered for each source side (after sorting by model weight) */
   public int num_translation_options = 20;
 
@@ -251,16 +251,16 @@ public class JoshuaConfiguration {
    * version of Sennrich (SSST 2014)
    */
   public boolean use_dot_chart = true;
-  
+
   /* Moses compatibility */
   public boolean moses = false;
-  
+
   /* If true, just print out the weights found in the config file, and exit. */
   public boolean show_weights_and_quit = false;
-  
+
   /* Read input from a file (Moses compatible flag) */
   public String input_file = null;
-  
+
   /* Write n-best output to this file */
   public String n_best_file = null;
 
@@ -269,17 +269,17 @@ public class JoshuaConfiguration {
 
   /* Weights overridden from the command line */
   public String weight_overwrite = "";
-  
+
   /**
    * This method resets the state of JoshuaConfiguration back to the state after initialization.
    * This is useful when for example making different calls to the decoder within the same java
    * program, which otherwise leads to potential errors due to inconsistent state as a result of
    * loading the configuration multiple times without resetting etc.
-   * 
+   *
    * This leads to the insight that in fact it may be an even better idea to refactor the code and
    * make JoshuaConfiguration an object that is is created and passed as an argument, rather than a
    * shared static object. This is just a suggestion for the next step.
-   * 
+   *
    */
   public void reset() {
     logger.info("Resetting the JoshuaConfiguration to its defaults ...");
@@ -289,7 +289,7 @@ public class JoshuaConfiguration {
     tms = new ArrayList<String>();
     weights_file = "";
     default_non_terminal = "[X]";
-    oovList = new ArrayList<OOVItem>(); 
+    oovList = new ArrayList<OOVItem>();
     oovList.add(new OOVItem(default_non_terminal, 1.0f));
     goal_symbol = "[GOAL]";
     amortized_sorting = true;
@@ -311,7 +311,7 @@ public class JoshuaConfiguration {
     features = new ArrayList<String>();
     weights = new ArrayList<String>();
     server_port = 0;
-    
+
     reordering_limit = 8;
     num_translation_options = 20;
     logger.info("...done");
@@ -353,8 +353,7 @@ public class JoshuaConfiguration {
       tmpFile.delete();
 
     } catch (IOException e) {
-      e.printStackTrace();
-      System.exit(1);
+      throw new RuntimeException(e);
     }
   }
 
@@ -364,7 +363,7 @@ public class JoshuaConfiguration {
     try {
       for (String line : configReader) {
         line = line.trim(); // .toLowerCase();
-        
+
         if (Regex.commentOrEmptyLine.matches(line))
           continue;
 
@@ -398,7 +397,7 @@ public class JoshuaConfiguration {
              *              
              * feature-function = StateMinimizingLanguageModel -lm_order 5 -lm_file lm.gz
              */
-            
+
             String[] tokens = fds[1].split("\\s+");
             if (tokens[2].equals("true"))
               features.add(String.format("feature_function = StateMinimizingLanguageModel -lm_type kenlm -lm_order %s -lm_file %s",
@@ -414,14 +413,14 @@ public class JoshuaConfiguration {
              *   tm = TYPE -owner OWNER -maxspan MAXSPAN -path PATH    
              */
             String tmLine = fds[1];
-            
+
             String[] tokens = fds[1].split("\\s+");
             if (! tokens[1].startsWith("-")) { // old format
               tmLine = String.format("%s -owner %s -maxspan %s -path %s", tokens[0], tokens[1], tokens[2], tokens[3]);
               Decoder.LOG(1, String.format("WARNING: Converting deprecated TM line from '%s' -> '%s'", fds[1], tmLine));
             }
             tms.add(tmLine);
-            
+
           } else if (parameter.equals("v")) {
             Decoder.VERBOSE = Integer.parseInt(fds[1]);
 
@@ -446,7 +445,7 @@ public class JoshuaConfiguration {
                     String[] tokens = str.trim().split("\\s+");
 
                     oovList.add(new OOVItem(FormatUtils.markup(tokens[0]),
-                            (float) Math.log(Float.parseFloat(tokens[1]))));
+                        (float) Math.log(Float.parseFloat(tokens[1]))));
 
                     str = br.readLine();
                   }
@@ -462,10 +461,8 @@ public class JoshuaConfiguration {
             } else {
               String[] tokens = fds[1].trim().split("\\s+");
               if (tokens.length % 2 != 0) {
-                  System.err.println(String.format("* FATAL: invalid format for '%s'", fds[0]));
-                  System.exit(1);
-                }
-
+                throw new RuntimeException(String.format("* FATAL: invalid format for '%s'", fds[0]));
+              }
               oovList = new ArrayList<OOVItem>();
 
               for (int i = 0; i < tokens.length; i += 2)
@@ -477,7 +474,7 @@ public class JoshuaConfiguration {
 
           } else if (parameter.equals(normalize_key("lattice-decoding"))) {
             lattice_decoding = true;
-            
+
           } else if (parameter.equals(normalize_key("segment-oovs"))) {
             segment_oovs = true;
             lattice_decoding = true;
@@ -542,13 +539,12 @@ public class JoshuaConfiguration {
             logger.finest(String.format("pop-limit: %s", pop_limit));
 
           } else if (parameter.equals(normalize_key("input-type"))) {
-            if (fds[1].equals("json"))
+            if (fds[1].equals("json")) {
               input_type = INPUT_TYPE.json;
-            else if (fds[1].equals("plain"))
+            } else if (fds[1].equals("plain")) {
               input_type = INPUT_TYPE.plain;
-            else {
-              System.err.println(String.format("* FATAL: invalid server type '%s'", fds[1]));
-              System.exit(1);
+            } else {
+              throw new RuntimeException(String.format("* FATAL: invalid server type '%s'", fds[1]));
             }
             logger.info(String.format("    input-type: %s", input_type));
 
@@ -559,7 +555,7 @@ public class JoshuaConfiguration {
               server_type = SERVER_TYPE.HTTP;
 
             logger.info(String.format("    server-type: %s", server_type));
-            
+
           } else if (parameter.equals(normalize_key("server-port"))) {
             server_port = Integer.parseInt(fds[1]);
             logger.info(String.format("    server-port: %d", server_port));
@@ -597,16 +593,16 @@ public class JoshuaConfiguration {
             fragmentMapFile = fds[1];
             Tree.readMapping(fragmentMapFile);
 
-          /** PHRASE-BASED PARAMETERS **/
+            /** PHRASE-BASED PARAMETERS **/
           } else if (parameter.equals(normalize_key("search"))) {
             search_algorithm = fds[1];
-            
+
             if (!search_algorithm.equals("cky") && !search_algorithm.equals("stack")) {
               throw new RuntimeException(
                   "-search must be one of 'stack' (for phrase-based decoding) " +
-                  "or 'cky' (for hierarchical / syntactic decoding)");
+                      "or 'cky' (for hierarchical / syntactic decoding)");
             }
-            
+
             if (search_algorithm.equals("cky") && include_align_index) {
               throw new RuntimeException(
                   "include_align_index is currently not supported with cky search");
@@ -617,13 +613,13 @@ public class JoshuaConfiguration {
 
           } else if (parameter.equals(normalize_key("num-translation-options"))) {
             num_translation_options = Integer.parseInt(fds[1]);
-            
+
           } else if (parameter.equals(normalize_key("no-dot-chart"))) {
             use_dot_chart = false;
-            
+
           } else if (parameter.equals(normalize_key("moses"))) {
             moses = true; // triggers some Moses-specific compatibility options
-            
+
           } else if (parameter.equals(normalize_key("show-weights"))) {
             show_weights_and_quit = true;
 
@@ -637,23 +633,23 @@ public class JoshuaConfiguration {
           } else if (parameter.equals(normalize_key("input-file"))) {
             // for Moses compatibility
             input_file = fds[1];
-            
+
           } else if (parameter.equals(normalize_key("weight-file"))) {
             // for Moses, ignore
 
           } else if (parameter.equals(normalize_key("weight-overwrite"))) {
             weight_overwrite = fds[1];
-            
+
           } else if (parameter.equals(normalize_key("source-annotations"))) {
             // Check source sentence
             source_annotations = true;
 
           } else if (parameter.equals(normalize_key("cached-rules-size"))) {
-              // Check source sentence
-              cachedRuleSize = Integer.parseInt(fds[1]);
+            // Check source sentence
+            cachedRuleSize = Integer.parseInt(fds[1]);
           } else if (parameter.equals(normalize_key("lowercase"))) {
             lowercase = true;
-            
+
           } else if (parameter.equals(normalize_key("project-case"))) {
             project_case = true;
 
@@ -669,8 +665,7 @@ public class JoshuaConfiguration {
               logger.warning(String.format("WARNING: ignoring deprecated parameter '%s'", fds[0]));
 
             } else {
-              logger.warning("FATAL: unknown configuration parameter '" + fds[0] + "'");
-              System.exit(1);
+              throw new RuntimeException("FATAL: unknown configuration parameter '" + fds[0] + "'");
             }
           }
 
@@ -701,7 +696,7 @@ public class JoshuaConfiguration {
    * equivalence classes on external use of parameter names, permitting arbitrary_under_scores and
    * camelCasing in paramter names without forcing the user to memorize them all. Here are some
    * examples of equivalent ways to refer to parameter names:
-   * 
+   *
    * {pop-limit, poplimit, PopLimit, popLimit, pop_lim_it} {lmfile, lm-file, LM-FILE, lm_file}
    */
   public static String normalize_key(String text) {

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/Translation.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/Translation.java b/src/main/java/org/apache/joshua/decoder/Translation.java
index 10852e5..5afae74 100644
--- a/src/main/java/org/apache/joshua/decoder/Translation.java
+++ b/src/main/java/org/apache/joshua/decoder/Translation.java
@@ -152,8 +152,7 @@ public class Translation {
 
         out.flush();
       } catch (IOException e) {
-        e.printStackTrace();
-        System.exit(1);
+        throw new RuntimeException(e);
       }
       
       this.output = sw.toString();

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/TargetBigram.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/TargetBigram.java b/src/main/java/org/apache/joshua/decoder/ff/TargetBigram.java
index 5661ce7..db70509 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/TargetBigram.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/TargetBigram.java
@@ -20,7 +20,7 @@ package org.apache.joshua.decoder.ff;
 
 import java.io.IOException;
 import java.util.HashSet;
-import java.util.LinkedList;	
+import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.joshua.corpus.Vocabulary;
@@ -36,32 +36,32 @@ import org.apache.joshua.util.io.LineReader;
 /***
  * The RuleBigram feature is an indicator feature that counts target word bigrams that are created when
  * a rule is applied. It accepts three parameters:
- * 
+ *
  * -vocab /path/to/vocab
- * 
+ *
  *  The path to a vocabulary, where each line is of the format ID WORD COUNT.
- *  
+ *
  * -threshold N
- * 
+ *
  *  Mask to UNK all words whose COUNT is less than N.
- *  
+ *
  * -top-n N
- * 
+ *
  *  Only use the top N words.
  */
 
 public class TargetBigram extends StatefulFF {
-  
+
   private HashSet<String> vocab = null;
   private int maxTerms = 1000000;
   private int threshold = 0;
 
   public TargetBigram(FeatureVector weights, String[] args, JoshuaConfiguration config) {
     super(weights, "TargetBigram", args, config);
-    
+
     if (parsedArgs.containsKey("threshold"))
       threshold = Integer.parseInt(parsedArgs.get("threshold"));
-    
+
     if (parsedArgs.containsKey("top-n"))
       maxTerms = Integer.parseInt(parsedArgs.get("top-n"));
 
@@ -72,11 +72,11 @@ public class TargetBigram extends StatefulFF {
 
   /**
    * Load vocabulary items passing the 'threshold' and 'top-n' filters.
-   * 
+   *
    * @param filename
    */
   private void loadVocab(String filename) {
-    this.vocab = new HashSet<String>(); 
+    this.vocab = new HashSet<String>();
     this.vocab.add("<s>");
     this.vocab.add("</s>");
     try {
@@ -84,18 +84,18 @@ public class TargetBigram extends StatefulFF {
       for (String line: lineReader) {
         if (lineReader.lineno() > maxTerms)
           break;
-        
+
         String[] tokens = line.split("\\s+");
         String word = tokens[1];
         int count = Integer.parseInt(tokens[2]);
-        
+
         if (count >= threshold)
           vocab.add(word);
       }
 
     } catch (IOException e) {
-      System.err.println(String.format("* FATAL: couldn't load TargetBigram vocabulary '%s'", filename));
-      System.exit(1);
+      throw new RuntimeException(String.format(
+          "* FATAL: couldn't load TargetBigram vocabulary '%s'", filename), e);
     }
   }
 
@@ -107,7 +107,7 @@ public class TargetBigram extends StatefulFF {
 
     int left = -1;
     int right = -1;
-    
+
     List<String> currentNgram = new LinkedList<String>();
     for (int c = 0; c < enWords.length; c++) {
       int curID = enWords[c];
@@ -127,7 +127,7 @@ public class TargetBigram extends StatefulFF {
           if (currentNgram.size() == 2) {
             String ngram = join(currentNgram);
             acc.add(String.format("%s_%s", name, ngram), 1);
-//            System.err.println(String.format("ADDING %s_%s", name, ngram));
+            //            System.err.println(String.format("ADDING %s_%s", name, ngram));
             currentNgram.remove(0);
           }
         }
@@ -144,20 +144,20 @@ public class TargetBigram extends StatefulFF {
         if (currentNgram.size() == 2) {
           String ngram = join(currentNgram);
           acc.add(String.format("%s_%s", name, ngram), 1);
-//          System.err.println(String.format("ADDING %s_%s", name, ngram));
+          //          System.err.println(String.format("ADDING %s_%s", name, ngram));
           currentNgram.remove(0);
         }
       }
     }
 
     NgramDPState state = new NgramDPState(new int[] { left }, new int[] { right });
-//    System.err.println(String.format("RULE %s -> state %s", rule.getRuleString(), state));
+    //    System.err.println(String.format("RULE %s -> state %s", rule.getRuleString(), state));
     return state;
   }
 
   /**
    * Returns the word after comparing against the private vocabulary (if set).
-   * 
+   *
    * @param curID
    * @return the word
    */
@@ -165,9 +165,9 @@ public class TargetBigram extends StatefulFF {
     String word = Vocabulary.word(curID);
 
     if (vocab != null && ! vocab.contains(word)) {
-      return "UNK"; 
+      return "UNK";
     }
-    
+
     return word;
   }
 
@@ -186,7 +186,7 @@ public class TargetBigram extends StatefulFF {
   @Override
   public DPState computeFinal(HGNode tailNode, int i, int j, SourcePath sourcePath,
       Sentence sentence, Accumulator acc) {
-    
+
     return tailNode.getDPState(stateIndex);
   }
 
@@ -200,7 +200,7 @@ public class TargetBigram extends StatefulFF {
 
   /**
    * Join a list with the _ character. I am sure this is in a library somewhere.
-   * 
+   *
    * @param list a list of strings
    * @return the joined String
    */

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/FragmentLMFF.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/FragmentLMFF.java b/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/FragmentLMFF.java
index e438778..c935eba 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/FragmentLMFF.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/FragmentLMFF.java
@@ -128,9 +128,8 @@ public class FragmentLMFF extends StatefulFF {
         // lmFragments.get(lmFragments.size()-1)));
       }
     } catch (IOException e) {
-      System.err.println(String.format("* WARNING: couldn't read fragment LM file '%s'",
-          fragmentLMFile));
-      System.exit(1);
+      throw new RuntimeException(String.format("* WARNING: couldn't read fragment LM file '%s'",
+          fragmentLMFile), e);
     }
     System.err.println(String.format("FragmentLMFF: Read %d LM fragments from '%s'", numFragments,
         fragmentLMFile));

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/Tree.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/Tree.java b/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/Tree.java
index 6214560..02741e4 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/Tree.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/fragmentlm/Tree.java
@@ -517,9 +517,8 @@ public class Tree implements Serializable {
         rulesToFragmentStrings.put(fields[1].trim(), fields[0].trim()); // buildFragment(fields[0]));
       }
     } catch (IOException e) {
-      System.err.println(String.format("* WARNING: couldn't read fragment mapping file '%s'",
-          fragmentMappingFile));
-      System.exit(1);
+      throw new RuntimeException(String.format("* WARNING: couldn't read fragment mapping file '%s'",
+          fragmentMappingFile), e);
     }
     System.err.println(String.format("FragmentLMFF: Read %d mappings from '%s'",
         rulesToFragmentStrings.size(), fragmentMappingFile));
@@ -729,13 +728,13 @@ public class Tree implements Serializable {
             frontierTree.children = tree.children;
           }
         } catch (IndexOutOfBoundsException e) {
+          //TODO: send these prints to LOG.err
           System.err.println(String.format("ERROR at index %d", i));
           System.err.println(String.format("RULE: %s  TREE: %s", rule.getEnglishWords(), tree));
           System.err.println("  FRONTIER:");
           for (Tree kid : frontier)
             System.err.println("    " + kid);
-          e.printStackTrace();
-          System.exit(1);
+          throw new RuntimeException(String.format("ERROR at index %d", i), e);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/lm/KenLM.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/lm/KenLM.java b/src/main/java/org/apache/joshua/decoder/ff/lm/KenLM.java
index 2c43712..e012421 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/lm/KenLM.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/lm/KenLM.java
@@ -38,13 +38,14 @@ public class KenLM implements NGramLanguageModel, Comparable<KenLM> {
     try {
       System.loadLibrary("ken");
     } catch (UnsatisfiedLinkError e) {
+      //TODO: send these prints to LOG.err
       System.err.println("* FATAL: Can't find libken.so (libken.dylib on OS X) in $JOSHUA/lib");
       System.err.println("*        This probably means that the KenLM library didn't compile.");
       System.err.println("*        Make sure that BOOST_ROOT is set to the root of your boost");
       System.err.println("*        installation (it's not /opt/local/, the default), change to");
       System.err.println("*        $JOSHUA, and type 'ant kenlm'. If problems persist, see the");
       System.err.println("*        website (joshua-decoder.org).");
-      System.exit(1);
+      throw new RuntimeException(e);
     }
   }
 
@@ -161,8 +162,7 @@ public class KenLM implements NGramLanguageModel, Comparable<KenLM> {
     try {
       estimate = estimateRule(pointer, words);
     } catch (NoSuchMethodError e) {
-      e.printStackTrace();
-      System.exit(1);
+      throw new RuntimeException(e);
     }
     
     return estimate;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/lm/LanguageModelFF.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/lm/LanguageModelFF.java b/src/main/java/org/apache/joshua/decoder/ff/lm/LanguageModelFF.java
index f2daffd..741fea6 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/lm/LanguageModelFF.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/lm/LanguageModelFF.java
@@ -173,9 +173,9 @@ public class LanguageModelFF extends StatefulFF {
       this.languageModel = new LMGrammarBerkeley(ngramOrder, path);
 
     } else {
-      System.err.println(String.format("* FATAL: Invalid backend lm_type '%s' for LanguageModel", type));
-      System.err.println(String.format("*        Permissible values for 'lm_type' are 'kenlm' and 'berkeleylm'"));
-      System.exit(-1);
+      String msg = String.format("* FATAL: Invalid backend lm_type '%s' for LanguageModel", type)
+          + "*        Permissible values for 'lm_type' are 'kenlm' and 'berkeleylm'";
+      throw new RuntimeException(msg);
     }
 
     Vocabulary.registerLanguageModel(this.languageModel);
@@ -278,8 +278,7 @@ public class LanguageModelFF extends StatefulFF {
    */
   protected int[] getClasses(Rule rule) {
     if (this.classMap == null) {
-      System.err.println("The class map is not set. Cannot use the class LM ");
-      System.exit(2);
+      throw new RuntimeException("The class map is not set. Cannot use the class LM ");
     }
     /* Very important to make a copy here, so the original rule is not modified */
     int[] tokens = Arrays.copyOf(rule.getEnglish(), rule.getEnglish().length);

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/lm/StateMinimizingLanguageModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/lm/StateMinimizingLanguageModel.java b/src/main/java/org/apache/joshua/decoder/ff/lm/StateMinimizingLanguageModel.java
index b3f6eca..9bf4cc7 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/lm/StateMinimizingLanguageModel.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/lm/StateMinimizingLanguageModel.java
@@ -49,9 +49,9 @@ public class StateMinimizingLanguageModel extends LanguageModelFF {
     super(weights, args, config);
     this.type = "kenlm";
     if (parsedArgs.containsKey("lm_type") && ! parsedArgs.get("lm_type").equals("kenlm")) {
-      System.err.println("* FATAL: StateMinimizingLanguageModel only supports 'kenlm' lm_type backend");
-      System.err.println("*        Remove lm_type from line or set to 'kenlm'");
-      System.exit(-1);
+      String msg = "* FATAL: StateMinimizingLanguageModel only supports 'kenlm' lm_type backend"
+          + "*        Remove lm_type from line or set to 'kenlm'";
+      throw new RuntimeException(msg);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeley.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeley.java b/src/main/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeley.java
index 6d80d93..859ca6a 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeley.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/lm/berkeley_lm/LMGrammarBerkeley.java
@@ -72,8 +72,7 @@ public class LMGrammarBerkeley extends DefaultNGramLanguageModel {
     vocabIdToMyIdMapping = new int[10];
 
     if (!new File(lm_file).exists()) {
-      System.err.println("Can't read lm_file '" + lm_file + "'");
-      System.exit(1);
+      throw new RuntimeException("Can't read lm_file '" + lm_file + "'");
     }
 
     if (logRequests) {

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java b/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
index c9a3214..abe115c 100644
--- a/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
+++ b/src/main/java/org/apache/joshua/decoder/ff/phrase/Distortion.java
@@ -37,9 +37,9 @@ public class Distortion extends StatelessFF {
     super(weights, "Distortion", args, config);
     
     if (! config.search_algorithm.equals("stack")) {
-      System.err.println("* FATAL: Distortion feature only application for phrase-based decoding");
-      System.err.println("         Use -search phrase or remove this feature");
-      System.exit(1);
+      String msg = "* FATAL: Distortion feature only application for phrase-based decoding. "
+          + "Use -search phrase or remove this feature";
+      throw new RuntimeException(msg);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/hypergraph/HGNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/hypergraph/HGNode.java b/src/main/java/org/apache/joshua/decoder/hypergraph/HGNode.java
index a38fec9..d9cd4a8 100644
--- a/src/main/java/org/apache/joshua/decoder/hypergraph/HGNode.java
+++ b/src/main/java/org/apache/joshua/decoder/hypergraph/HGNode.java
@@ -241,9 +241,7 @@ public class HGNode {
    */
   // sort by estTotalLogP: for pruning purpose
   public int compareTo(HGNode anotherItem) {
-    System.out.println("HGNode, compare functiuon should never be called");
-    System.exit(1);
-    return 0;
+    throw new RuntimeException("HGNode, compare functiuon should never be called");
     /*
      * if (this.estTotalLogP > anotherItem.estTotalLogP) { return -1; } else if (this.estTotalLogP
      * == anotherItem.estTotalLogP) { return 0; } else { return 1; }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/phrase/PhraseTable.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/phrase/PhraseTable.java b/src/main/java/org/apache/joshua/decoder/phrase/PhraseTable.java
index db76924..c937b50 100644
--- a/src/main/java/org/apache/joshua/decoder/phrase/PhraseTable.java
+++ b/src/main/java/org/apache/joshua/decoder/phrase/PhraseTable.java
@@ -60,9 +60,9 @@ public class PhraseTable implements Grammar {
     if (grammarFile != null && new File(grammarFile).isDirectory()) {
       this.backend = new PackedGrammar(grammarFile, spanLimit, owner, type, config);
       if (this.backend.getMaxSourcePhraseLength() == -1) {
-        System.err.println("FATAL: Using a packed grammar for a phrase table backend requires that you");
-        System.err.println("       packed the grammar with Joshua 6.0.2 or greater");
-        System.exit(-1);
+        String msg = "FATAL: Using a packed grammar for a phrase table backend requires that you "
+            + "packed the grammar with Joshua 6.0.2 or greater";
+        throw new RuntimeException(msg);
       }
 
     } else {

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/decoder/segment_file/Sentence.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/decoder/segment_file/Sentence.java b/src/main/java/org/apache/joshua/decoder/segment_file/Sentence.java
index 2f45ced..d3a5e79 100644
--- a/src/main/java/org/apache/joshua/decoder/segment_file/Sentence.java
+++ b/src/main/java/org/apache/joshua/decoder/segment_file/Sentence.java
@@ -410,8 +410,7 @@ public class Sentence {
     if (this.sourceLattice == null) {
       if (config.lattice_decoding && rawSource().startsWith("(((")) {
         if (config.search_algorithm.equals("stack")) {
-          System.err.println("* FATAL: lattice decoding currently not supported for stack-based search algorithm.");
-          System.exit(12);
+          throw new RuntimeException("* FATAL: lattice decoding currently not supported for stack-based search algorithm.");
         }
         this.sourceLattice = Lattice.createTokenLatticeFromPLF(rawSource(), config);
       } else

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/BLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/BLEU.java b/src/main/java/org/apache/joshua/metrics/BLEU.java
index a37dcaf..1d14d36 100644
--- a/src/main/java/org/apache/joshua/metrics/BLEU.java
+++ b/src/main/java/org/apache/joshua/metrics/BLEU.java
@@ -49,7 +49,7 @@ public class BLEU extends EvaluationMetric {
       setMaxGramLength(mxGrmLn);
     } else {
       logger.severe("Maximum gram length must be positive");
-      System.exit(1);
+      throw new RuntimeException("Maximum gram length must be positive");
     }
 
     if (methodStr.equals("closest")) {
@@ -62,7 +62,7 @@ public class BLEU extends EvaluationMetric {
       logger.severe("Unknown effective length method string " + methodStr + ".");
       // System.out.println("Should be one of closest, shortest, or average.");
       logger.severe("Should be one of closest or shortest.");
-      System.exit(1);
+      throw new RuntimeException("Should be one of closest or shortest.");
     }
 
     initialize();
@@ -261,9 +261,10 @@ public class BLEU extends EvaluationMetric {
 
   public double score(int[] stats) {
     if (stats.length != suffStatsCount) {
-      logger.severe("Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
-          + suffStatsCount + ") in BLEU.score(int[])");
-      System.exit(2);
+      String msg = "Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
+          + suffStatsCount + ") in BLEU.score(int[])";
+      logger.severe(msg);
+      throw new RuntimeException(msg);
     }
 
     double BLEUsum = 0.0;

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/EvaluationMetric.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/EvaluationMetric.java b/src/main/java/org/apache/joshua/metrics/EvaluationMetric.java
index 4ca1675..cce51f8 100644
--- a/src/main/java/org/apache/joshua/metrics/EvaluationMetric.java
+++ b/src/main/java/org/apache/joshua/metrics/EvaluationMetric.java
@@ -303,9 +303,8 @@ public abstract class EvaluationMetric {
       outFile.close();
 
     } catch (IOException e) {
-      System.err.println("IOException in EvaluationMetric.createSuffStatsFile(...): "
-          + e.getMessage());
-      System.exit(99902);
+      throw new RuntimeException("IOException in EvaluationMetric.createSuffStatsFile(...): "
+          + e.getMessage(), e);
     }
 
   }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/GradeLevelBLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/GradeLevelBLEU.java b/src/main/java/org/apache/joshua/metrics/GradeLevelBLEU.java
index da9f549..8c0366c 100644
--- a/src/main/java/org/apache/joshua/metrics/GradeLevelBLEU.java
+++ b/src/main/java/org/apache/joshua/metrics/GradeLevelBLEU.java
@@ -59,8 +59,7 @@ public class GradeLevelBLEU extends BLEU {
     try {
       loadSources(options[2]);
     } catch (IOException e) {
-      logger.severe("Error loading the source sentences from " + options[2]);
-      System.exit(1);
+      throw new RuntimeException("Error loading the source sentences from " + options[2], e);
     }
     if (useBLEUplus) srcBLEU = new SourceBLEU(4, "closest", srcIndex, true);
     initialize();
@@ -183,9 +182,10 @@ public class GradeLevelBLEU extends BLEU {
 
   public double score(int[] stats) {
     if (stats.length != suffStatsCount) {
-      logger.severe("Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
-          + suffStatsCount + ") in BLEU.score(int[])");
-      System.exit(2);
+      String msg = "Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
+          + suffStatsCount + ") in BLEU.score(int[])";
+      logger.severe(msg);
+      throw new RuntimeException(msg);
     }
     double BLEUscore = super.score(stats);
     double candGL =