From 18a9205a04a4371ae33565694f151a25a82a3db4 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Mon, 18 Oct 2010 23:54:09 +0000 Subject: [PATCH] Added an exception class to indicate IO Errors. --- .../java/com/google/gson/JsonIOException.java | 44 +++++++++++++++++++ .../com/google/gson/JsonParseException.java | 2 +- .../main/java/com/google/gson/Streams.java | 3 +- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gson/src/main/java/com/google/gson/JsonIOException.java diff --git a/gson/src/main/java/com/google/gson/JsonIOException.java b/gson/src/main/java/com/google/gson/JsonIOException.java new file mode 100644 index 00000000..1e6612d3 --- /dev/null +++ b/gson/src/main/java/com/google/gson/JsonIOException.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.gson; + +/** + * This exception is raised when Gson was unable to read an input stream + * or write to one. + * + * @author Inderjeet Singh + * @author Joel Leitch + */ +public final class JsonIOException extends JsonParseException { + + public JsonIOException(String msg) { + super(msg); + } + + public JsonIOException(String msg, Throwable cause) { + super(msg, cause); + } + + /** + * Creates exception with the specified cause. Consider using + * {@link #JsonIOException(String, Throwable)} instead if you can describe what happened. + * + * @param cause root exception that caused this exception to be thrown. + */ + public JsonIOException(Throwable cause) { + super(cause); + } +} diff --git a/gson/src/main/java/com/google/gson/JsonParseException.java b/gson/src/main/java/com/google/gson/JsonParseException.java index 0b733a70..084f6612 100644 --- a/gson/src/main/java/com/google/gson/JsonParseException.java +++ b/gson/src/main/java/com/google/gson/JsonParseException.java @@ -29,7 +29,7 @@ package com.google.gson; * @author Inderjeet Singh * @author Joel Leitch */ -public final class JsonParseException extends RuntimeException { +public class JsonParseException extends RuntimeException { static final long serialVersionUID = -4086729973971783390L; /** diff --git a/gson/src/main/java/com/google/gson/Streams.java b/gson/src/main/java/com/google/gson/Streams.java index 99d5a80a..59eb8a02 100644 --- a/gson/src/main/java/com/google/gson/Streams.java +++ b/gson/src/main/java/com/google/gson/Streams.java @@ -18,6 +18,7 @@ package com.google.gson; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; + import java.io.EOFException; import java.io.IOException; import java.io.Writer; @@ -71,7 +72,7 @@ final class Streams { if (e instanceof EOFException) { return JsonNull.createJsonNull(); } - throw new JsonParseException(e); + throw new JsonIOException(e); } catch (NumberFormatException e) { throw new JsonParseException(e); }