Web サイトから画像を取得するメソッドを持つ Java クラスがあります。
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;
}
問題は、取得しようとしている imageUri がリダイレクトされ、ImageIcon コンストラクターが java.lang.SecurityException をスローすることがあります。これは catch 句によってキャッチされず、プログラムが終了します。
この例外をキャッチする方法を誰かが提案できますか?
ありがとう