Better exceptions from JSON parsing. Project: http://git-wip-us.apache.org/repos/asf/jena/repo Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/f53761da Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/f53761da Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/f53761da
Branch: refs/heads/master Commit: f53761daa5bf8bd1228cdd55d3ea2e144c7b739e Parents: ac8a7d9 Author: Andy Seaborne <a...@apache.org> Authored: Sat Nov 8 16:16:50 2014 +0000 Committer: Andy Seaborne <a...@apache.org> Committed: Sat Nov 8 16:16:50 2014 +0000 ---------------------------------------------------------------------- .../main/java/org/apache/jena/atlas/io/IO.java | 3 ++- .../java/org/apache/jena/atlas/json/JSON.java | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jena/blob/f53761da/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java b/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java index f49e0f6..4d52fe2 100644 --- a/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java +++ b/jena-arq/src/main/java/org/apache/jena/atlas/io/IO.java @@ -64,8 +64,9 @@ public class IO * If the filename ends in .gz, wrap in GZIPInputStream * @param filename * @throws FileNotFoundException + * @throws IOException */ - static public InputStream openFileEx(String filename) throws IOException { + static public InputStream openFileEx(String filename) throws IOException, FileNotFoundException { if ( filename == null || filename.equals("-") ) return System.in ; if ( filename.startsWith("file:") ) http://git-wip-us.apache.org/repos/asf/jena/blob/f53761da/jena-arq/src/main/java/org/apache/jena/atlas/json/JSON.java ---------------------------------------------------------------------- diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/json/JSON.java b/jena-arq/src/main/java/org/apache/jena/atlas/json/JSON.java index 63b680e..df3727f 100644 --- a/jena-arq/src/main/java/org/apache/jena/atlas/json/JSON.java +++ b/jena-arq/src/main/java/org/apache/jena/atlas/json/JSON.java @@ -61,20 +61,15 @@ public class JSON /** Read a JSON object from a file */ public static JsonObject read(String filename) { - try - { - try (InputStream in = IO.openFileEx( filename )) - { - return JSON.parse( in ); - } + try (InputStream in = IO.openFileEx(filename)) { + return JSON.parse(in) ; } - catch (FileNotFoundException ex) - { - throw new RuntimeException("File not found: "+filename, ex) ; + catch (FileNotFoundException ex) { + IO.exception("File not found: " + filename, ex) ; + return null ; } - catch (IOException ex) - { - IO.exception("IOException: "+filename, ex); + catch (IOException ex) { + IO.exception("IOException: " + filename, ex) ; return null ; } }