From ba4a159e344a62082fffb885ce1498751cc04eec Mon Sep 17 00:00:00 2001 From: Jason Long Date: Sat, 17 Jan 2015 08:45:45 -0800 Subject: [PATCH] Animation: catch IOExceptions from loading dependent images --- src/micropolisj/graphics/Animation.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/micropolisj/graphics/Animation.java b/src/micropolisj/graphics/Animation.java index c8d0b89..818c038 100644 --- a/src/micropolisj/graphics/Animation.java +++ b/src/micropolisj/graphics/Animation.java @@ -45,7 +45,7 @@ public class Animation extends TileImage } public static Animation read(XMLStreamReader in, LoaderContext ctx) - throws XMLStreamException, IOException + throws XMLStreamException { Animation a = new Animation(); a.load(in, ctx); @@ -60,7 +60,7 @@ public class Animation extends TileImage } void load(XMLStreamReader in, LoaderContext ctx) - throws XMLStreamException, IOException + throws XMLStreamException { while (in.nextTag() != XMLStreamConstants.END_ELEMENT) { assert in.isStartElement(); @@ -71,8 +71,16 @@ public class Animation extends TileImage String tmp = in.getAttributeValue(null, "duration"); int duration = tmp != null ? Integer.parseInt(tmp) : DEFAULT_DURATION; - tmp = in.getElementText(); - addFrame( ctx.parseFrameSpec(tmp), duration ); + String text = in.getElementText(); + TileImage frameImage; + try { + frameImage = ctx.parseFrameSpec(text); + } + catch (IOException e) { + throw new XMLStreamException("Unable to load frame image: "+text, e); + } + + addFrame( frameImage, duration ); } else { // unrecognized element