catch undeclared exception in higher method.

This commit is contained in:
Yoshihiro OKUMURA 2022-10-07 19:13:15 +09:00
parent dab69b174f
commit a4bd4b0b96
3 changed files with 15 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
<artifactId>bioformats-imageinfo</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
<name>bioformats-imageinfo</name>
<url>https://neurodata.riken.jp</url>
@ -130,6 +130,7 @@
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>

View File

@ -259,9 +259,9 @@ public class BioFormatsImageInfo {
DebugTools.enableLogging("ERROR");
format = readMetadata(path, metadata);
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
} catch (BioFormatsImageException e) {
} catch (Throwable t) {
status = false;
message = e.getMessage();
message = t.getMessage();
metadata.clear();
thumbnail.clear();
}

View File

@ -108,7 +108,10 @@ public class BioFormatsImageThumbnail {
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
final ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
if (param.canWriteCompressed()) {
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(0.0f);
}
writer.setOutput(ios);
writer.write(null, new IIOImage(image, null, null), param);
writer.dispose();
@ -169,13 +172,13 @@ public class BioFormatsImageThumbnail {
// System.out.println("resolution: " + reader.getResolutionCount());
// System.out.println("thubmail series: " + series);
ret = reader.openThumbImage(no);
} catch (final Throwable e) {
for (Throwable t = e; t != null; t = t.getCause()) {
} catch (final Throwable t) {
for (Throwable e = t; e != null; e = e.getCause()) {
if (t instanceof OutOfMemoryError) {
throw new BioFormatsImageException("out of memory");
}
}
throw new BioFormatsImageException(e);
throw new BioFormatsImageException(t);
} finally {
try {
reader.close();
@ -226,7 +229,7 @@ public class BioFormatsImageThumbnail {
thumbnail.put("height", height);
thumbnail.put("mimeType", mimeType);
thumbnail.put("url", dataUri);
} catch (final BioFormatsImageException e) {
} catch (final Throwable t) {
// ignore
ret = false;
}
@ -234,7 +237,7 @@ public class BioFormatsImageThumbnail {
return ret;
}
public static void main(final String[] args) throws BioFormatsImageException {
public static void main(final String[] args) {
if (args.length != 1) {
System.out.println("filename argument required");
System.exit(1);
@ -248,8 +251,8 @@ public class BioFormatsImageThumbnail {
final String dataUri = getDataUri(image, "image/" + format);
System.out.println(dataUri);
// saveFile(dataUri, "/var/tmp/thumbnail." + format);
} catch (final BioFormatsImageException e) {
System.out.println(e.getMessage());
} catch (final Throwable t) {
System.out.println(t.getMessage());
System.exit(1);
}
}