JAL-4195 catch thrown exceptions (if any) during image export and report as an error.
authorJames Procter <j.procter@dundee.ac.uk>
Wed, 7 Jun 2023 16:13:55 +0000 (17:13 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Wed, 7 Jun 2023 16:13:55 +0000 (17:13 +0100)
src/jalview/bin/Commands.java
src/jalview/io/HTMLOutput.java
src/jalview/io/exceptions/ImageOutputException.java [new file with mode: 0644]

index 64c1e72..b9c04f5 100644 (file)
@@ -44,6 +44,7 @@ import jalview.io.FileLoader;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
 import jalview.io.NewickFile;
+import jalview.io.exceptions.ImageOutputException;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemeProperty;
 import jalview.structure.StructureImportSettings.TFType;
@@ -737,7 +738,7 @@ public class Commands
         Cache.setProperty("EXPORT_EMBBED_BIOJSON", "false");
 
         Console.info("Writing " + file);
-
+        try {
         switch (type)
         {
 
@@ -786,6 +787,9 @@ public class Commands
                   + "' not known. Ignoring");
           break;
         }
+        } catch (Exception ioex) {
+          Console.warn("Unexpected error during export",ioex);
+        }
       }
     }
     return true;
index ed80eb9..d659e2a 100644 (file)
@@ -34,6 +34,7 @@ import jalview.datamodel.AlignExportSettingsAdapter;
 import jalview.datamodel.AlignmentExportData;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.IProgressIndicator;
+import jalview.io.exceptions.ImageOutputException;
 import jalview.util.MessageManager;
 
 public abstract class HTMLOutput implements Runnable
@@ -302,12 +303,12 @@ public abstract class HTMLOutput implements Runnable
     return generatedFile;
   }
 
-  public void exportHTML(String outputFile)
+  public void exportHTML(String outputFile) throws ImageOutputException
   {
     exportHTML(outputFile, null);
   }
 
-  public void exportHTML(String outputFile, String renderer)
+  public void exportHTML(String outputFile, String renderer) throws ImageOutputException
   {
     setProgressMessage(MessageManager.formatMessage(
             "status.exporting_alignment_as_x_file", getDescription()));
@@ -358,5 +359,5 @@ public abstract class HTMLOutput implements Runnable
   }
 
   // used to pass an option such as render to run
-  public abstract void run(String string);
+  public abstract void run(String string) throws ImageOutputException;
 }
\ No newline at end of file
diff --git a/src/jalview/io/exceptions/ImageOutputException.java b/src/jalview/io/exceptions/ImageOutputException.java
new file mode 100644 (file)
index 0000000..bf06494
--- /dev/null
@@ -0,0 +1,36 @@
+package jalview.io.exceptions;
+
+/**
+ * wrapper for passing error messages and exceptions back to UI when image io goes wrong
+ * @author jprocter
+ *
+ */
+public class ImageOutputException extends Exception
+{
+
+  public ImageOutputException()
+  {
+  }
+
+  public ImageOutputException(String message)
+  {
+    super(message);
+  }
+
+  public ImageOutputException(Throwable cause)
+  {
+    super(cause);
+  }
+
+  public ImageOutputException(String message, Throwable cause)
+  {
+    super(message, cause);
+  }
+
+  public ImageOutputException(String message, Throwable cause,
+          boolean enableSuppression, boolean writableStackTrace)
+  {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+}