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:05 UTC
[2/6] incubator-joshua git commit: System.exit() removed and replaced
with RuntimeException(...)
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/METEOR.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/METEOR.java b/src/main/java/org/apache/joshua/metrics/METEOR.java
index 7ed0796..33232db 100644
--- a/src/main/java/org/apache/joshua/metrics/METEOR.java
+++ b/src/main/java/org/apache/joshua/metrics/METEOR.java
@@ -52,9 +52,9 @@ public class METEOR extends EvaluationMetric {
} else if (Metric_options[0].equals("es")) {
targetLanguage = "es";
} else {
- System.out.println("Unknown language string " + Metric_options[0] + ".");
- System.out.println("Should be one of {en,cz,fr,de,es}.");
- System.exit(1);
+ String msg = "Unknown language string " + Metric_options[0]
+ + ". Should be one of {en,cz,fr,de,es}.";
+ throw new RuntimeException(msg);
}
if (Metric_options[1].equals("norm_yes")) {
@@ -62,9 +62,9 @@ public class METEOR extends EvaluationMetric {
} else if (Metric_options[1].equals("norm_no")) {
normalize = false;
} else {
- System.out.println("Unknown normalize string " + Metric_options[1] + ".");
- System.out.println("Should be one of norm_yes or norm_no.");
- System.exit(1);
+ String msg = "Unknown normalize string " + Metric_options[1]
+ + ". Should be one of norm_yes or norm_no.";
+ throw new RuntimeException(msg);
}
if (Metric_options[2].equals("keepPunc")) {
@@ -72,15 +72,14 @@ public class METEOR extends EvaluationMetric {
} else if (Metric_options[1].equals("removePunk")) {
keepPunctuation = false;
} else {
- System.out.println("Unknown keepPunctuation string " + Metric_options[1] + ".");
- System.out.println("Should be one of keepPunc or removePunk.");
- System.exit(1);
+ String msg = "Unknown keepPunctuation string " + Metric_options[1]
+ + ". Should be one of keepPunc or removePunk.";
+ throw new RuntimeException(msg);
}
maxComputations = Integer.parseInt(Metric_options[3]);
if (maxComputations < 1) {
- System.out.println("Maximum computations must be positive");
- System.exit(2);
+ throw new RuntimeException("Maximum computations must be positive");
}
initialize(); // set the data members of the metric
@@ -124,7 +123,7 @@ public class METEOR extends EvaluationMetric {
// 1a) Create hypothesis file
FileOutputStream outStream = new FileOutputStream("hyp.txt.METEOR", false); // false: don't
- // append
+ // append
OutputStreamWriter outStreamWriter = new OutputStreamWriter(outStream, "utf8");
BufferedWriter outFile = new BufferedWriter(outStreamWriter);
@@ -191,15 +190,10 @@ public class METEOR extends EvaluationMetric {
stats[d][3] = (int) Double.parseDouble(strA[3]);
stats[d][4] = (int) Double.parseDouble(strA[4]);
}
-
+
inFile.close();
- } catch (IOException e) {
- System.err.println("IOException in METEOR.suffStats(String[],int[]): " + e.getMessage());
- System.exit(99902);
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in METEOR.suffStats(String[],int[]): "
- + e.getMessage());
- System.exit(99903);
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
}
return stats;
@@ -207,9 +201,8 @@ public class METEOR extends EvaluationMetric {
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- System.out.println("Mismatch between stats.length and suffStatsCount (" + stats.length
+ throw new RuntimeException("Mismatch between stats.length and suffStatsCount (" + stats.length
+ " vs. " + suffStatsCount + ") in METEOR.score(int[])");
- System.exit(1);
}
double sc = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/MinimumChangeBLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/MinimumChangeBLEU.java b/src/main/java/org/apache/joshua/metrics/MinimumChangeBLEU.java
index c759d0e..908e266 100644
--- a/src/main/java/org/apache/joshua/metrics/MinimumChangeBLEU.java
+++ b/src/main/java/org/apache/joshua/metrics/MinimumChangeBLEU.java
@@ -171,9 +171,10 @@ public class MinimumChangeBLEU 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 accuracy = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/Precis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/Precis.java b/src/main/java/org/apache/joshua/metrics/Precis.java
index 5bdd4c7..6db1d66 100644
--- a/src/main/java/org/apache/joshua/metrics/Precis.java
+++ b/src/main/java/org/apache/joshua/metrics/Precis.java
@@ -241,9 +241,10 @@ public class Precis extends BLEU {
// calculate the actual score from the statistics
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- logger.severe("Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
- + suffStatsCount + ") in Precis.score(int[])");
- System.exit(2);
+ String msg = "Mismatch between stats.length and suffStatsCount (" + stats.length + " vs. "
+ + suffStatsCount + ") in Precis.score(int[])";
+ logger.severe(msg);
+ throw new RuntimeException(msg);
}
double accuracy = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/PrecisMinusSourceBLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/PrecisMinusSourceBLEU.java b/src/main/java/org/apache/joshua/metrics/PrecisMinusSourceBLEU.java
index 461243c..bfe15d0 100644
--- a/src/main/java/org/apache/joshua/metrics/PrecisMinusSourceBLEU.java
+++ b/src/main/java/org/apache/joshua/metrics/PrecisMinusSourceBLEU.java
@@ -132,16 +132,14 @@ public class PrecisMinusSourceBLEU extends EvaluationMetric {
fd = new File(outputFileName + ".SRC_BLEU");
if (fd.exists()) fd.delete();
} catch (IOException e) {
- System.err.println("IOException: " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- System.out.println("Mismatch between stats.length and suffStatsCount (" + stats.length
+ throw new RuntimeException("Mismatch between stats.length and suffStatsCount (" + stats.length
+ " vs. " + suffStatsCount + ") in PrecisMinusSourceBLEU.score(int[])");
- System.exit(1);
}
double sc = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/TER.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/TER.java b/src/main/java/org/apache/joshua/metrics/TER.java
index 2e37c11..0dcf9d9 100644
--- a/src/main/java/org/apache/joshua/metrics/TER.java
+++ b/src/main/java/org/apache/joshua/metrics/TER.java
@@ -57,9 +57,9 @@ public class TER extends EvaluationMetric {
} else if (Metric_options[0].equals("nocase")) {
caseSensitive = false;
} else {
- System.out.println("Unknown case sensitivity string " + Metric_options[0] + ".");
- System.out.println("Should be one of case or nocase.");
- System.exit(1);
+ String msg = "Unknown case sensitivity string " + Metric_options[0]
+ + ". Should be one of case or nocase.";
+ throw new RuntimeException(msg);
}
if (Metric_options[1].equals("punc")) {
@@ -67,41 +67,37 @@ public class TER extends EvaluationMetric {
} else if (Metric_options[1].equals("nopunc")) {
withPunctuation = false;
} else {
- System.out.println("Unknown with-punctuation string " + Metric_options[1] + ".");
- System.out.println("Should be one of punc or nopunc.");
- System.exit(1);
+ String msg = "Unknown with-punctuation string " + Metric_options[1]
+ + ". Should be one of punc or nopunc.";
+ throw new RuntimeException(msg);
}
beamWidth = Integer.parseInt(Metric_options[2]);
if (beamWidth < 1) {
- System.out.println("Beam width must be positive");
- System.exit(1);
+ throw new RuntimeException("Beam width must be positive");
}
maxShiftDist = Integer.parseInt(Metric_options[3]);
if (maxShiftDist < 1) {
- System.out.println("Maximum shift distance must be positive");
- System.exit(1);
+ throw new RuntimeException("Maximum shift distance must be positive");
}
tercomJarFileName = Metric_options[4];
if (tercomJarFileName == null || tercomJarFileName.equals("")) {
- System.out.println("Problem processing tercom's jar filename");
- System.exit(1);
+ throw new RuntimeException("Problem processing tercom's jar filename");
} else {
File checker = new File(tercomJarFileName);
if (!checker.exists()) {
- System.out.println("Could not find tercom jar file " + tercomJarFileName);
- System.out.println("(Please make sure you use the full path in the filename)");
- System.exit(1);
+ String msg = "Could not find tercom jar file " + tercomJarFileName
+ + "(Please make sure you use the full path in the filename)";
+ throw new RuntimeException(msg);
}
}
numScoringThreads = Integer.parseInt(Metric_options[5]);
if (numScoringThreads < 1) {
- System.out.println("Number of TER scoring threads must be positive");
- System.exit(1);
+ throw new RuntimeException("Number of TER scoring threads must be positive");
}
@@ -206,8 +202,7 @@ public class TER extends EvaluationMetric {
if (fd.exists()) fd.delete();
} catch (IOException e) {
- System.err.println("IOException in TER.suffStats(String[],int[]): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return stats;
@@ -259,9 +254,7 @@ public class TER extends EvaluationMetric {
try {
blocker.acquire(batchCount);
} catch (java.lang.InterruptedException e) {
- System.err.println("InterruptedException in TER.createSuffStatsFile(...): "
- + e.getMessage());
- System.exit(99906);
+ throw new RuntimeException(e);
}
PrintWriter outFile = new PrintWriter(outputFileName);
@@ -275,8 +268,7 @@ public class TER extends EvaluationMetric {
outFile.close();
} catch (IOException e) {
- System.err.println("IOException in TER.createSuffStatsFile(...): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -317,8 +309,7 @@ public class TER extends EvaluationMetric {
outFile.close();
} catch (IOException e) {
- System.err.println("IOException in TER.createTercomHypFile(...): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException("IOException in TER.createTercomHypFile(...): " + e.getMessage(), e);
}
return readCount;
@@ -367,8 +358,7 @@ public class TER extends EvaluationMetric {
outFile.close();
} catch (IOException e) {
- System.err.println("IOException in TER.createTercomRefFile(...): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return readCount;
@@ -407,12 +397,8 @@ public class TER extends EvaluationMetric {
exitValue = p.waitFor();
- } catch (IOException e) {
- System.err.println("IOException in TER.runTercom(...): " + e.getMessage());
- System.exit(99902);
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in TER.runTercom(...): " + e.getMessage());
- System.exit(99903);
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
}
return exitValue;
@@ -438,16 +424,14 @@ public class TER extends EvaluationMetric {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in TER.copySS(String,PrintWriter): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- System.out.println("Mismatch between stats.length and suffStatsCount (" + stats.length
+ throw new RuntimeException("Mismatch between stats.length and suffStatsCount (" + stats.length
+ " vs. " + suffStatsCount + ") in TER.score(int[])");
- System.exit(2);
}
double sc = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/TERMinusBLEU.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/TERMinusBLEU.java b/src/main/java/org/apache/joshua/metrics/TERMinusBLEU.java
index 5208546..bd40140 100644
--- a/src/main/java/org/apache/joshua/metrics/TERMinusBLEU.java
+++ b/src/main/java/org/apache/joshua/metrics/TERMinusBLEU.java
@@ -144,16 +144,14 @@ public class TERMinusBLEU extends EvaluationMetric {
fd = new File(outputFileName + ".BLEU");
if (fd.exists()) fd.delete();
} catch (IOException e) {
- System.err.println("IOException in TER.createTercomHypFile(...): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException("IOException in TER.createTercomHypFile(...): " + e.getMessage());
}
}
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- System.out.println("Mismatch between stats.length and suffStatsCount (" + stats.length
+ throw new RuntimeException("Mismatch between stats.length and suffStatsCount (" + stats.length
+ " vs. " + suffStatsCount + ") in TERMinusBLEU.score(int[])");
- System.exit(1);
}
double sc = 0.0;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/TercomRunner.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/TercomRunner.java b/src/main/java/org/apache/joshua/metrics/TercomRunner.java
index 75a76dc..d7eeae5 100644
--- a/src/main/java/org/apache/joshua/metrics/TercomRunner.java
+++ b/src/main/java/org/apache/joshua/metrics/TercomRunner.java
@@ -96,12 +96,8 @@ public class TercomRunner implements Runnable {
fd = new File(refFileName);
if (fd.exists()) fd.delete();
- } catch (IOException e) {
- System.err.println("IOException in TER.runTercom(...): " + e.getMessage());
- System.exit(99902);
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in TER.runTercom(...): " + e.getMessage());
- System.exit(99903);
+ } catch (IOException| InterruptedException e) {
+ throw new RuntimeException(e);
}
blocker.release();
@@ -112,8 +108,7 @@ public class TercomRunner implements Runnable {
try {
real_run();
} catch (Exception e) {
- System.err.println("Exception in TercomRunner.run(): " + e.getMessage());
- System.exit(99905);
+ throw new RuntimeException(e);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/metrics/ZeroOneLoss.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/metrics/ZeroOneLoss.java b/src/main/java/org/apache/joshua/metrics/ZeroOneLoss.java
index 3d4b616..aee6bcc 100644
--- a/src/main/java/org/apache/joshua/metrics/ZeroOneLoss.java
+++ b/src/main/java/org/apache/joshua/metrics/ZeroOneLoss.java
@@ -66,9 +66,8 @@ public class ZeroOneLoss extends EvaluationMetric {
public double score(int[] stats) {
if (stats.length != suffStatsCount) {
- System.out.println("Mismatch between stats.length and suffStatsCount (" + stats.length
+ throw new RuntimeException("Mismatch between stats.length and suffStatsCount (" + stats.length
+ " vs. " + suffStatsCount + ") in ZeroOneLoss.score(int[])");
- System.exit(1);
}
return 1.0 - (stats[0] / (double) stats[1]);
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/mira/MIRACore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/mira/MIRACore.java b/src/main/java/org/apache/joshua/mira/MIRACore.java
index 045353a..db689bd 100755
--- a/src/main/java/org/apache/joshua/mira/MIRACore.java
+++ b/src/main/java/org/apache/joshua/mira/MIRACore.java
@@ -327,12 +327,8 @@ public class MIRACore {
}
inFile_names.close();
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
// the parameter file contains one line per parameter
@@ -390,12 +386,8 @@ public class MIRACore {
inFile_comm.close();
}
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
// set static data members for the EvaluationMetric class
@@ -1491,16 +1483,11 @@ public class MIRACore {
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 MIRACore.run_decoder(int): " + e.getMessage());
- System.exit(99902);
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in MIRACore.run_decoder(int): " + e.getMessage());
- System.exit(99903);
+ } catch (IOException| InterruptedException e) {
+ throw new RuntimeException(e);
}
retSA[0] = decoderOutFileName;
@@ -1598,13 +1585,8 @@ public class MIRACore {
gzipFile(featsFileName);
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.produceTempFiles(int): "
- + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.produceTempFiles(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -1652,9 +1634,7 @@ public class MIRACore {
inFile.close();
outFile.close();
} catch (IOException e) {
- System.err.println("IOException in MIRACore.createConfigFile(double[],String,String): "
- + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -1664,8 +1644,7 @@ public class MIRACore {
try {
inFile_init = new Scanner(new FileReader(paramsFileName));
} catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.processParamFile(): " + e.getMessage());
- System.exit(99901);
+ throw new RuntimeException(e);
}
String dummy = "";
@@ -1688,8 +1667,7 @@ public class MIRACore {
} 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
@@ -1704,25 +1682,22 @@ public class MIRACore {
// 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]
- + "=maxRandValue[" + c + "]!");
- System.exit(21);
+ throw new RuntimeException("minRandValue[" + c + "]=" + minRandValue[c]
+ + " > " + maxRandValue[c] + "=maxRandValue[" + c + "]!");
}
// check for odd values
@@ -1773,40 +1748,35 @@ public class MIRACore {
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();
@@ -1918,12 +1888,8 @@ public class MIRACore {
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.processDocInfo(): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.processDocInfo(): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2024,8 +1990,7 @@ public class MIRACore {
outFile_lambdas.close();
} catch (IOException e) {
- System.err.println("IOException in MIRACore.finish(): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2106,23 +2071,15 @@ public class MIRACore {
argsVector.add(paramA[opt]);
}
} else {
- println("Malformed line in config file:");
- println(origLine);
- System.exit(70);
+ throw new RuntimeException("Malformed line in config file:" + origLine);
}
}
} while (line != null);
inFile.close();
- } catch (FileNotFoundException e) {
- println("MIRA configuration file " + fileName + " was not found!");
- System.err.println("FileNotFoundException in MIRACore.cfgFileToArgsArray(String): "
- + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.cfgFileToArgsArray(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
String[] argsArray = new String[argsVector.size()];
@@ -2200,14 +2157,12 @@ public class MIRACore {
} 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];
@@ -2227,8 +2182,7 @@ public class MIRACore {
}
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];
@@ -2273,32 +2227,27 @@ public class MIRACore {
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]);
@@ -2309,20 +2258,17 @@ public class MIRACore {
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]);
@@ -2331,8 +2277,7 @@ public class MIRACore {
} 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]);
@@ -2341,8 +2286,7 @@ public class MIRACore {
} 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")) {
@@ -2364,8 +2308,7 @@ public class MIRACore {
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
@@ -2376,8 +2319,7 @@ public class MIRACore {
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
@@ -2388,8 +2330,7 @@ public class MIRACore {
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.");
}
}
// run perceptron or not
@@ -2400,8 +2341,7 @@ public class MIRACore {
else if (per == 0)
runPercep = false;
else {
- println("-runPercep must be either 0 or 1.");
- System.exit(10);
+ throw new RuntimeException("-runPercep must be either 0 or 1.");
}
}
// oracle selection mode
@@ -2434,8 +2374,7 @@ public class MIRACore {
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]);
@@ -2444,8 +2383,7 @@ public class MIRACore {
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]);
@@ -2454,8 +2392,7 @@ public class MIRACore {
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]);
@@ -2467,8 +2404,7 @@ public class MIRACore {
} 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")) {
@@ -2480,35 +2416,30 @@ public class MIRACore {
} 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;
@@ -2580,10 +2511,10 @@ public class MIRACore {
if (!canRunCommand && !canRunJoshua) { // can only run fake decoder
if (!canRunFake) {
- println("MIRA 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 = "MIRA 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;
@@ -2596,9 +2527,8 @@ public class MIRACore {
}
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 "
@@ -2690,8 +2620,7 @@ public class MIRACore {
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!");
}
}
@@ -2726,8 +2655,7 @@ public class MIRACore {
deleteFile(inputFileName);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.gzipFile(String,String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2759,8 +2687,7 @@ public class MIRACore {
deleteFile(gzippedFileName);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.gunzipFile(String,String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2776,8 +2703,7 @@ public class MIRACore {
if (!checker.exists()) {
checker = new File(prefix + ".1");
if (!checker.exists()) {
- println("Can't find reference files.");
- System.exit(50);
+ throw new RuntimeException("Can't find reference files.");
} else {
prefix = prefix + ".";
}
@@ -2806,8 +2732,7 @@ public class MIRACore {
for (int r = 0; r < numFiles; ++r) {
if (countLines(prefix + nextIndex) != lineCount) {
- println("Line count mismatch in " + (prefix + nextIndex) + ".");
- System.exit(60);
+ throw new RuntimeException("Line count mismatch in " + (prefix + nextIndex) + ".");
}
InputStream inStream = new FileInputStream(new File(prefix + nextIndex));
inFile[r] = new BufferedReader(new InputStreamReader(inStream, "utf8"));
@@ -2828,14 +2753,8 @@ public class MIRACore {
for (int r = 0; r < numFiles; ++r) {
inFile[r].close();
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MIRACore.createUnifiedRefFile(String,int): "
- + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MIRACore.createUnifiedRefFile(String,int): "
- + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return outFileName;
@@ -2988,8 +2907,7 @@ public class MIRACore {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in MIRACore.countLines(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return count;
@@ -3010,8 +2928,7 @@ public class MIRACore {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in MIRACore.countNonEmptyLines(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return count;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/pro/ClassifierMegaM.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/pro/ClassifierMegaM.java b/src/main/java/org/apache/joshua/pro/ClassifierMegaM.java
index 4817290..f75605f 100755
--- a/src/main/java/org/apache/joshua/pro/ClassifierMegaM.java
+++ b/src/main/java/org/apache/joshua/pro/ClassifierMegaM.java
@@ -72,8 +72,7 @@ public class ClassifierMegaM implements ClassifierInterface {
int decStatus = p.waitFor();
if (decStatus != 0) {
- System.out.println("Call to decoder returned " + decStatus + "; was expecting " + 0 + ".");
- System.exit(30);
+ throw new RuntimeException("Call to decoder returned " + decStatus + "; was expecting " + 0 + ".");
}
// read the weights
@@ -86,11 +85,8 @@ public class ClassifierMegaM implements ClassifierInterface {
file.delete();
file = new File(weightFilePath);
file.delete();
- } catch (IOException exception) {
- exception.getStackTrace();
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in MertCore.run_decoder(int): " + e.getMessage());
- System.exit(99903);;
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
}
System.out.println("------- MegaM training ends ------");
@@ -111,8 +107,7 @@ public class ClassifierMegaM implements ClassifierInterface {
*/
public void setClassifierParam(String[] param) {
if (param == null) {
- System.out.println("ERROR: must provide parameters for MegaM classifier!");
- System.exit(10);
+ throw new RuntimeException("ERROR: must provide parameters for MegaM classifier!");
} else {
commandFilePath = param[0];
trainingFilePath = param[1];
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/pro/ClassifierSVM.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/pro/ClassifierSVM.java b/src/main/java/org/apache/joshua/pro/ClassifierSVM.java
index a1fe91a..5c1f4e3 100755
--- a/src/main/java/org/apache/joshua/pro/ClassifierSVM.java
+++ b/src/main/java/org/apache/joshua/pro/ClassifierSVM.java
@@ -73,8 +73,8 @@ public class ClassifierSVM implements ClassifierInterface {
int decStatus = p.waitFor();
if (decStatus != 0) {
- System.out.println("Call to decoder returned " + decStatus + "; was expecting " + 0 + ".");
- System.exit(30);
+ throw new RuntimeException("Call to decoder returned " + decStatus + "; was expecting "
+ + 0 + ".");
}
// read the model file
@@ -109,11 +109,8 @@ public class ClassifierSVM implements ClassifierInterface {
file.delete();
file = new File(modelFilePath);
file.delete();
- } catch (IOException exception) {
- exception.getStackTrace();
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in MertCore.run_decoder(int): " + e.getMessage());
- System.exit(99903);;
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
}
System.out.println("------- SVM training ends ------");
@@ -129,8 +126,7 @@ public class ClassifierSVM implements ClassifierInterface {
*/
public void setClassifierParam(String[] param) {
if (param == null) {
- System.out.println("ERROR: must provide parameters for LibSVM classifier!");
- System.exit(10);
+ throw new RuntimeException("ERROR: must provide parameters for LibSVM classifier!");
} else {
commandFilePath = param[0];
trainingFilePath = param[1];
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/pro/Optimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/pro/Optimizer.java b/src/main/java/org/apache/joshua/pro/Optimizer.java
index ff7d902..ad80305 100755
--- a/src/main/java/org/apache/joshua/pro/Optimizer.java
+++ b/src/main/java/org/apache/joshua/pro/Optimizer.java
@@ -99,18 +99,9 @@ public class Optimizer {
// System.out.println(output);
return finalLambda;
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- System.exit(50);
- } catch (InstantiationException e) {
- e.printStackTrace();
- System.exit(55);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- System.exit(60);
+ } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
}
-
- return null;
}
public double computeCorpusMetricScore(double[] finalLambda) {
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/pro/PROCore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/pro/PROCore.java b/src/main/java/org/apache/joshua/pro/PROCore.java
index e378e9d..24bee52 100755
--- a/src/main/java/org/apache/joshua/pro/PROCore.java
+++ b/src/main/java/org/apache/joshua/pro/PROCore.java
@@ -320,12 +320,8 @@ public class PROCore {
}
inFile_names.close();
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in PROCore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
// the parameter file contains one line per parameter
@@ -383,12 +379,8 @@ public class PROCore {
inFile_comm.close();
}
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in PROCore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
// set static data members for the EvaluationMetric class
@@ -1465,16 +1457,11 @@ public class PROCore {
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 PROCore.run_decoder(int): " + e.getMessage());
- System.exit(99902);
- } catch (InterruptedException e) {
- System.err.println("InterruptedException in PROCore.run_decoder(int): " + e.getMessage());
- System.exit(99903);
+ } catch (IOException | InterruptedException e) {
+ throw new RuntimeException(e);
}
retSA[0] = decoderOutFileName;
@@ -1572,13 +1559,8 @@ public class PROCore {
gzipFile(featsFileName);
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.produceTempFiles(int): "
- + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in PROCore.produceTempFiles(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -1626,9 +1608,7 @@ public class PROCore {
inFile.close();
outFile.close();
} catch (IOException e) {
- System.err.println("IOException in PROCore.createConfigFile(double[],String,String): "
- + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -1638,8 +1618,7 @@ public class PROCore {
try {
inFile_init = new Scanner(new FileReader(paramsFileName));
} catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.processParamFile(): " + e.getMessage());
- System.exit(99901);
+ throw new RuntimeException(e);
}
String dummy = "";
@@ -1662,8 +1641,7 @@ public class PROCore {
} 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
@@ -1678,25 +1656,22 @@ public class PROCore {
// 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
@@ -1747,40 +1722,34 @@ public class PROCore {
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();
@@ -1892,12 +1861,8 @@ public class PROCore {
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.processDocInfo(): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in PROCore.processDocInfo(): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -1998,8 +1963,7 @@ public class PROCore {
outFile_lambdas.close();
} catch (IOException e) {
- System.err.println("IOException in PROCore.finish(): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2080,9 +2044,7 @@ public class PROCore {
argsVector.add(paramA[opt]);
}
} else {
- println("Malformed line in config file:");
- println(origLine);
- System.exit(70);
+ throw new RuntimeException("Malformed line in config file:" + origLine);
}
}
@@ -2091,12 +2053,9 @@ public class PROCore {
inFile.close();
} catch (FileNotFoundException e) {
println("PRO configuration file " + fileName + " was not found!");
- System.err.println("FileNotFoundException in PROCore.cfgFileToArgsArray(String): "
- + e.getMessage());
- System.exit(99901);
+ throw new RuntimeException(e);
} catch (IOException e) {
- System.err.println("IOException in PROCore.cfgFileToArgsArray(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
String[] argsArray = new String[argsVector.size()];
@@ -2174,14 +2133,12 @@ public class PROCore {
} 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];
@@ -2201,8 +2158,7 @@ public class PROCore {
}
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];
@@ -2247,32 +2203,27 @@ public class PROCore {
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("maxMERTIts must be positive.");
- System.exit(10);
+ throw new RuntimeException("maxMERTIts must be positive.");
}
} else if (option.equals("-minIt")) {
minMERTIterations = Integer.parseInt(args[i + 1]);
if (minMERTIterations < 1) {
- println("minMERTIts must be positive.");
- System.exit(10);
+ throw new RuntimeException("minMERTIts must be positive.");
}
} else if (option.equals("-prevIt")) {
prevMERTIterations = Integer.parseInt(args[i + 1]);
if (prevMERTIterations < 0) {
- println("prevMERTIts must be non-negative.");
- System.exit(10);
+ throw new RuntimeException("prevMERTIts must be non-negative.");
}
} else if (option.equals("-stopIt")) {
stopMinIts = Integer.parseInt(args[i + 1]);
if (stopMinIts < 1) {
- println("stopMinIts must be positive.");
- System.exit(10);
+ throw new RuntimeException("stopMinIts must be positive.");
}
} else if (option.equals("-stopSig")) {
stopSigValue = Double.parseDouble(args[i + 1]);
@@ -2283,20 +2234,17 @@ public class PROCore {
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]);
@@ -2305,8 +2253,7 @@ public class PROCore {
} 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]);
@@ -2315,8 +2262,7 @@ public class PROCore {
} 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")) {
@@ -2355,8 +2301,7 @@ public class PROCore {
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.");
}
}
// interpolation coefficient between current & previous weights
@@ -2374,8 +2319,7 @@ public class PROCore {
} 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")) {
@@ -2387,35 +2331,30 @@ public class PROCore {
} 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;
@@ -2487,10 +2426,10 @@ public class PROCore {
if (!canRunCommand && !canRunJoshua) { // can only run fake decoder
if (!canRunFake) {
- println("PRO 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 = "PRO 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;
@@ -2503,9 +2442,8 @@ public class PROCore {
}
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 "
@@ -2597,8 +2535,7 @@ public class PROCore {
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!");
}
}
@@ -2633,8 +2570,7 @@ public class PROCore {
deleteFile(inputFileName);
} catch (IOException e) {
- System.err.println("IOException in PROCore.gzipFile(String,String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2666,8 +2602,7 @@ public class PROCore {
deleteFile(gzippedFileName);
} catch (IOException e) {
- System.err.println("IOException in PROCore.gunzipFile(String,String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
}
@@ -2683,8 +2618,7 @@ public class PROCore {
if (!checker.exists()) {
checker = new File(prefix + ".1");
if (!checker.exists()) {
- println("Can't find reference files.");
- System.exit(50);
+ throw new RuntimeException("Can't find reference files.");
} else {
prefix = prefix + ".";
}
@@ -2713,8 +2647,7 @@ public class PROCore {
for (int r = 0; r < numFiles; ++r) {
if (countLines(prefix + nextIndex) != lineCount) {
- println("Line count mismatch in " + (prefix + nextIndex) + ".");
- System.exit(60);
+ throw new RuntimeException("Line count mismatch in " + (prefix + nextIndex) + ".");
}
InputStream inStream = new FileInputStream(new File(prefix + nextIndex));
inFile[r] = new BufferedReader(new InputStreamReader(inStream, "utf8"));
@@ -2735,14 +2668,8 @@ public class PROCore {
for (int r = 0; r < numFiles; ++r) {
inFile[r].close();
}
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in PROCore.createUnifiedRefFile(String,int): "
- + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in PROCore.createUnifiedRefFile(String,int): "
- + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return outFileName;
@@ -2895,8 +2822,7 @@ public class PROCore {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in PROCore.countLines(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return count;
@@ -2917,8 +2843,7 @@ public class PROCore {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in PROCore.countNonEmptyLines(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return count;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/server/TcpServer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/server/TcpServer.java b/src/main/java/org/apache/joshua/server/TcpServer.java
index 137794d..36dc957 100644
--- a/src/main/java/org/apache/joshua/server/TcpServer.java
+++ b/src/main/java/org/apache/joshua/server/TcpServer.java
@@ -58,8 +58,8 @@ public class TcpServer {
serverSocket.close();
} catch (IOException e) {
- System.err.println(String.format("Could not listen on port: %d.", joshuaConfiguration.server_port));
- System.exit(-1);
+ throw new RuntimeException(String.format("Could not listen on port: %d.",
+ joshuaConfiguration.server_port));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/tools/GrammarPacker.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/tools/GrammarPacker.java b/src/main/java/org/apache/joshua/tools/GrammarPacker.java
index 0b5985d..d32ab53 100644
--- a/src/main/java/org/apache/joshua/tools/GrammarPacker.java
+++ b/src/main/java/org/apache/joshua/tools/GrammarPacker.java
@@ -104,8 +104,7 @@ public class GrammarPacker {
if (!packAlignments) {
logger.info("No alignments file or grammar specified, skipping.");
} else if (alignments != null && !new File(alignments_filename).exists()) {
- logger.severe("Alignments file does not exist: " + alignments);
- System.exit(1);
+ throw new RuntimeException("Alignments file does not exist: " + alignments);
}
if (config_filename != null) {
@@ -119,8 +118,7 @@ public class GrammarPacker {
File working_dir = new File(output);
working_dir.mkdir();
if (!working_dir.exists()) {
- logger.severe("Failed creating output directory.");
- System.exit(1);
+ throw new RuntimeException("Failed creating output directory.");
}
}
@@ -136,8 +134,7 @@ public class GrammarPacker {
String[] fields = line.split("[\\s]+");
if (fields.length < 2) {
- logger.severe("Incomplete line in config.");
- System.exit(1);
+ throw new RuntimeException("Incomplete line in config.");
}
if ("slice_size".equals(fields[0])) {
// Number of records to concurrently load into memory for sorting.
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/util/FileUtility.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/FileUtility.java b/src/main/java/org/apache/joshua/util/FileUtility.java
index db6e9d9..0c504f8 100644
--- a/src/main/java/org/apache/joshua/util/FileUtility.java
+++ b/src/main/java/org/apache/joshua/util/FileUtility.java
@@ -118,11 +118,8 @@ public class FileUtility {
File f1 = new File(srFile);
File f2 = new File(dtFile);
copyFile(f1, f2);
- } catch (FileNotFoundException ex) {
- System.out.println(ex.getMessage() + " in the specified directory.");
- System.exit(0);
} catch (IOException e) {
- System.out.println(e.getMessage());
+ throw new RuntimeException(e);
}
}
@@ -145,11 +142,8 @@ public class FileUtility {
in.close();
out.close();
System.out.println("File copied.");
- } catch (FileNotFoundException ex) {
- System.out.println(ex.getMessage() + " in the specified directory.");
- System.exit(0);
} catch (IOException e) {
- System.out.println(e.getMessage());
+ throw new RuntimeException(e);
}
}
@@ -227,8 +221,7 @@ public class FileUtility {
* Method to handle standard IO xceptions. catch (Exception e) {Utility.handleIO_exception(e);}
*/
public static void handleExceptions(Exception e) {
- e.printStackTrace();
- System.exit(-1);
+ throw new RuntimeException(e);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/util/JoshuaEval.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/JoshuaEval.java b/src/main/java/org/apache/joshua/util/JoshuaEval.java
index 2a0b44c..3171641 100644
--- a/src/main/java/org/apache/joshua/util/JoshuaEval.java
+++ b/src/main/java/org/apache/joshua/util/JoshuaEval.java
@@ -102,13 +102,11 @@ public class JoshuaEval {
// testIndex=candPerSen means last candidate should be evaluated
if (inFileFormat.equals("plain") && candPerSen < 1) {
- println("candPerSen must be positive for a file in plain format.");
- System.exit(30);
+ throw new RuntimeException("candPerSen must be positive for a file in plain format.");
}
if (inFileFormat.equals("plain") && (testIndex < 1 || testIndex > candPerSen)) {
- println("For the plain format, testIndex must be in [1,candPerSen]");
- System.exit(31);
+ throw new RuntimeException("For the plain format, testIndex must be in [1,candPerSen]");
}
@@ -170,8 +168,7 @@ public class JoshuaEval {
if (line == null) {
println("Not enough candidates in " + inFileName + " to extract the " + candRank
+ "'th candidate for each sentence.");
- println("(Failed to extract one for the " + i + "'th sentence (0-indexed).)");
- System.exit(32);
+ throw new RuntimeException("(Failed to extract one for the " + i + "'th sentence (0-indexed).)");
}
int read_i = Integer.parseInt(line.substring(0, line.indexOf(" |||")).trim());
@@ -188,30 +185,25 @@ public class JoshuaEval {
n = 1;
i += 1;
} else {
- println("Not enough candidates in " + inFileName + " to extract the " + candRank
- + "'th candidate for each sentence.");
- println("(Failed to extract one for the " + i + "'th sentence (0-indexed).)");
- System.exit(32);
+ String msg = "Not enough candidates in " + inFileName + " to extract the " + candRank
+ + "'th candidate for each sentence. (Failed to extract one for the "
+ + i + "'th sentence (0-indexed).)";
+ throw new RuntimeException(msg);
}
} // while (line != null)
if (i != numSentences) {
- println("Not enough candidates were found (i = " + i + "; was expecting " + numSentences
+ throw new RuntimeException("Not enough candidates were found (i = " + i + "; was expecting " + numSentences
+ ")");
- System.exit(33);
}
} // nbest format
inFile.close();
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MertCore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MertCore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
@@ -296,28 +288,24 @@ public class JoshuaEval {
} else if (option.equals("-format")) {
candFileFormat = args[argno + 1];
if (!candFileFormat.equals("plain") && !candFileFormat.equals("nbest")) {
- println("candFileFormat must be either plain or nbest.");
- System.exit(10);
+ throw new RuntimeException("candFileFormat must be either plain or nbest.");
}
} else if (option.equals("-rank")) {
candRank = Integer.parseInt(args[argno + 1]);
if (refsPerSen < 1) {
- println("Argument for -rank must be positive.");
- System.exit(10);
+ throw new RuntimeException("Argument for -rank must be positive.");
}
} else if (option.equals("-ref")) {
refFileName = args[argno + 1];
} else if (option.equals("-rps")) {
refsPerSen = Integer.parseInt(args[argno + 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[argno + 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("-m")) {
metricName = args[argno + 1];
@@ -329,8 +317,7 @@ public class JoshuaEval {
}
argno += optionCount;
} else {
- println("Unknown metric name " + metricName + ".");
- System.exit(10);
+ throw new RuntimeException("Unknown metric name " + metricName + ".");
}
} else if (option.equals("-evr")) {
int evr = Integer.parseInt(args[argno + 1]);
@@ -339,8 +326,7 @@ public class JoshuaEval {
} else if (evr == 0) {
evaluateRefs = false;
} else {
- println("evalRefs must be either 0 or 1.");
- System.exit(10);
+ throw new RuntimeException("evalRefs must be either 0 or 1.");
}
} else if (option.equals("-v")) {
int v = Integer.parseInt(args[argno + 1]);
@@ -349,12 +335,10 @@ public class JoshuaEval {
} else if (v == 0) {
verbose = false;
} else {
- println("verbose must be either 0 or 1.");
- System.exit(10);
+ throw new RuntimeException("verbose must be either 0 or 1.");
}
} else {
- println("Unknown option " + option);
- System.exit(10);
+ throw new RuntimeException("Unknown option " + option);
}
argno += 2;
@@ -366,8 +350,7 @@ public class JoshuaEval {
if (! new File(refFile).exists())
refFile = refFileName + ".0";
if (! new File(refFile).exists()) {
- System.err.println(String.format("* FATAL: can't find first reference file '%s{0,.0}'", refFileName));
- System.exit(1);
+ throw new RuntimeException(String.format("* FATAL: can't find first reference file '%s{0,.0}'", refFileName));
}
numSentences = countLines(refFile);
@@ -390,8 +373,7 @@ public class JoshuaEval {
if (! new File(refFile).exists())
refFile = refFileName + "." + i;
if (! new File(refFile).exists()) {
- System.err.println(String.format("* FATAL: can't find reference file '%s'", refFile));
- System.exit(1);
+ throw new RuntimeException(String.format("* FATAL: can't find reference file '%s'", refFile));
}
reference_readers[i] = new BufferedReader(new InputStreamReader(new FileInputStream(new File(refFile)), "utf8"));
@@ -409,12 +391,8 @@ public class JoshuaEval {
for (int i = 0; i < refsPerSen; i++)
reference_readers[i].close();
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in JoshuaEval.processArgsAndInitialize(): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in JoshuaEval.processArgsAndInitialize(): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
// set static data members for the EvaluationMetric class
@@ -587,8 +565,7 @@ public class JoshuaEval {
inFile.close();
} catch (IOException e) {
- System.err.println("IOException in MertCore.countLines(String): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
return count;
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/util/SocketUtility.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/SocketUtility.java b/src/main/java/org/apache/joshua/util/SocketUtility.java
index 965a606..c3d923c 100644
--- a/src/main/java/org/apache/joshua/util/SocketUtility.java
+++ b/src/main/java/org/apache/joshua/util/SocketUtility.java
@@ -64,15 +64,8 @@ public class SocketUtility {
// res.data_out = new DataOutputStream(new BufferedOutputStream
// (res.socket.getOutputStream()));
- } catch (UnknownHostException e) {
- System.out.println("unknown host exception");
- System.exit(1);
- } catch (SocketTimeoutException e) {
- System.out.println("socket timeout exception");
- System.exit(1);
- } catch (IOException e) {
- System.out.println("io exception");
- System.exit(1);
+ } catch ( IOException e) {
+ throw new RuntimeException(e);
}
return res;
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java b/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
index 5f71f90..df729ed 100644
--- a/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
+++ b/src/main/java/org/apache/joshua/util/encoding/EncoderConfiguration.java
@@ -152,11 +152,9 @@ public class EncoderConfiguration {
}
} catch (ArrayIndexOutOfBoundsException e) {
- System.err.println("Usage: EncoderConfiguration <packed_directory>");
- System.exit(1);
+ throw new RuntimeException("Usage: EncoderConfiguration <packed_directory>");
} catch (IOException e) {
- System.err.println(String.format("* FATAL: can't find file %s/encoding", grammar_dir));
- System.exit(1);
+ throw new RuntimeException(String.format("* FATAL: can't find file %s/encoding", grammar_dir));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java b/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
index f480ec1..9cf1cc4 100644
--- a/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
+++ b/src/main/java/org/apache/joshua/util/encoding/FeatureTypeAnalyzer.java
@@ -74,8 +74,7 @@ public class FeatureTypeAnalyzer {
if ("encoder".equals(fields[0])) {
// Adding an encoder to the mix.
if (fields.length < 3) {
- logger.severe("Incomplete encoder line in config.");
- System.exit(0);
+ throw new RuntimeException("Incomplete encoder line in config.");
}
String encoder_key = fields[1];
ArrayList<Integer> feature_ids = new ArrayList<Integer>();
http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/9848541f/src/main/java/org/apache/joshua/zmert/IntermediateOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/joshua/zmert/IntermediateOptimizer.java b/src/main/java/org/apache/joshua/zmert/IntermediateOptimizer.java
index a22f9e7..333f937 100644
--- a/src/main/java/org/apache/joshua/zmert/IntermediateOptimizer.java
+++ b/src/main/java/org/apache/joshua/zmert/IntermediateOptimizer.java
@@ -613,12 +613,8 @@ public class IntermediateOptimizer implements Runnable {
inFile.close();
- } catch (FileNotFoundException e) {
- System.err.println("FileNotFoundException in MertCore.initialize(int): " + e.getMessage());
- System.exit(99901);
} catch (IOException e) {
- System.err.println("IOException in MertCore.initialize(int): " + e.getMessage());
- System.exit(99902);
+ throw new RuntimeException(e);
}
} // set_suffStats_array(HashMap[] suffStats_array, TreeSet[] indicesOfInterest, Vector[]
@@ -961,13 +957,7 @@ public class IntermediateOptimizer implements Runnable {
}
public void run() {
- try {
- real_run();
- } catch (Exception e) {
- System.err.println("Exception in IntermediateOptimizer.run(): " + e.getMessage());
- e.printStackTrace();
- System.exit(99905);
- }
+ real_run();
if (!strToPrint.equals("")) {
threadOutput.add(strToPrint);
}