ChineSouad / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Document thrown exceptions #246

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Look in the javadoc for gson.toJson(Object src, Appendable writer) or any of 
the methods serializing to a writer.

What is the expected output? What do you see instead?
I would like to know what exception to expect if there is any problem writing 
to the writer.

There is no such information currently.

What version of the product are you using? On what operating system?
source code from trunk.

Please provide any additional information below.
The methods will wrap any IOException in a very generic RuntimeException. IMHO 
it would be better to create a new exception for this problem; 
JsonSerializationException, maybe. But in any case, the javadoc should specify 
what to expect.

Original issue reported on code.google.com by albin.th...@gmail.com on 4 Oct 2010 at 1:53

GoogleCodeExporter commented 9 years ago
We added two new Exceptions in Gson 1.6: JsonIOException and 
JsonSyntaxException. Both of these are subclasses of JsonParseException. If you 
have suggestions on improving this design please let us know as soon as 
possible before we release Gson 1.6 publicly.

Original comment by inder123 on 3 Nov 2010 at 12:21

GoogleCodeExporter commented 9 years ago
I think that sounds great. That's exactly what I was looking for.

Two things, though:

1. There are still two methods that need to be changed:
public void toJson(JsonElement jsonElement, Appendable writer)
public void toJson(Object src, Appendable writer)

2. I have no problems with using unchecked exceptions, but there must be a way 
for the user of the API to know which exceptions can be thrown. Either add them 
to the javadoc for the methods or to the method signature, i.e.:

public void toJson(JsonElement jsonElement, Appendable writer) throws 
JsonIOException

or both. :-)

Thanks for a great API!

Original comment by albin.th...@gmail.com on 3 Nov 2010 at 6:56

GoogleCodeExporter commented 9 years ago
Thanks for the suggestion. r642 declares the exceptions that can be thrown by a 
method.

Original comment by inder123 on 3 Nov 2010 at 7:47

GoogleCodeExporter commented 9 years ago
Excellent!

Great work!

Original comment by albin.th...@gmail.com on 3 Nov 2010 at 10:20