DimDoors icon indicating copy to clipboard operation
DimDoors copied to clipboard

JsonSyntaxException is not an IOException

Open HenryLoenwind opened this issue 6 years ago • 2 comments

https://github.com/DimensionalDevelopment/DimDoors/blob/1.12-WIP/src/main/java/org/dimdev/dimdoors/shared/pockets/SchematicHandler.java#L95

com.google.gson.JsonSyntaxException (extends JsonParseException extends RuntimeException) is not an IOException, so that catch is quite useless for parser exceptions and the resulting crash is missing any kind of hint what is happening.

HenryLoenwind avatar Nov 03 '19 19:11 HenryLoenwind

CompressedStreamTools.readCompressed throws an IOException if I recall correctly. It should be thrown when the file doesn't exist

BoogieMonster1O1 avatar Oct 05 '20 04:10 BoogieMonster1O1

Yes, that catch itself is useful for when the file doesn't exist or cannot be opened. But if there's an error inside the file you will get a JsonParseException. Letting that one bubble up to top level will not give you any context information like file.getName(). So you'll have absolutely no idea where the error happened.

Note quite as useless as a catch (Throwable t) { println("There was an error"); exit(0); } but not far removed. ;)

HenryLoenwind avatar Oct 07 '20 18:10 HenryLoenwind