Hi all,
I have java class with a method which gets an image from a website:
private Image image;
private int height;
private int width;
private String imageUri;
public Image getImage() {
if (image == null) {
log.info("Fetching image: " + imageUri);
try {
URL iURL = new URL(imageUri);
ImageIcon ii = new ImageIcon(iURL);
image = ii.getImage();
height = image.getHeight(null);
width = image.getWidth(null);
} catch (SecurityException e) {
log.error("Unable to fetch image: " + imageUri,e);
} catch (MalformedURLException e) {
log.error("Unable to fetch image: " + imageUri,e);
}
}
return image;
}
The problem is that sometimes the imageUri I try to fetch gets redirected, causing the ImageIcon constructor to throw a java.lang.SecurityException - which is not caught by the catch clause, causing my program to terminate.
Can anyone suggest how I might catch this exception?
Thanks