diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-05-15 16:40:46 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-05-15 16:40:46 +0200 |
commit | bb1941650805ea7772082ee2724b98bb8154148e (patch) | |
tree | da29625e487f77563476c1d2c36e0a62b31fc280 | |
parent | f94162b0c8e6a7b7bd62087f14fcb1c646a6fe84 (diff) | |
download | Goldfarmer-bb1941650805ea7772082ee2724b98bb8154148e.tar.gz |
Catch a more specific NoSuchElementException, fix lexicon reading
-rw-r--r-- | src/main/Analyzor.java | 5 | ||||
-rw-r--r-- | src/main/FarmShell.java | 13 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 9be1101..b4fbae7 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -2,6 +2,7 @@ package main; import database.NamedPreparedStatement; import database.QueryUtils; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; @@ -43,8 +44,8 @@ public class Analyzor { // A unigram is in the format (WS = whitespace): // word <WS> rating <WS> ??? <WS> ?? // A bigram has an two WS-separated words instead of one. - try (Scanner uniScanner = new Scanner("unigrams-pmilexicon.txt"); - Scanner biScanner = new Scanner("bigrams-pmilexicon.txt");) { + try (Scanner uniScanner = new Scanner(new File("unigrams-pmilexicon.txt")); + Scanner biScanner = new Scanner(new File("bigrams-pmilexicon.txt"));) { //Fill the map of unigrams while (uniScanner.hasNext()) { String words = uniScanner.next(); diff --git a/src/main/FarmShell.java b/src/main/FarmShell.java index 3c6f17f..7186c2f 100644 --- a/src/main/FarmShell.java +++ b/src/main/FarmShell.java @@ -64,8 +64,6 @@ public class FarmShell { // print prompt for reading next line printPrompt(); } - // prevent corrupted compressed files when exiting without a command - throw new NoSuchElementException(); } /** @@ -102,8 +100,13 @@ public class FarmShell { System.err.println("Command " + args[0] + " failed with " + ex); ex.printStackTrace(); } catch (NoSuchElementException ex) { - // thrown by the "exit" command to signal exit - return false; + if ("EXIT NOW".equals(ex.getMessage())) { + // thrown by the "exit" command to signal exit + return false; + } else { + System.err.println("ZOMG SOMETHIGN FAILED: " + ex.getMessage()); + ex.printStackTrace(); + } } catch (SQLException ex) { System.err.println("such " + ex); } @@ -145,7 +148,7 @@ public class FarmShell { } break; case exit: - throw new NoSuchElementException(); + throw new NoSuchElementException("EXIT NOW"); default: throw new AssertionError(command.name()); } |